1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-04-14 02:29:23 +02:00

dspace_statistics_api/indexer.py: don't use psycopg2.extras.execute_values()

In psycopg version 3 we can use cursor.executemany().
This commit is contained in:
Alan Orth 2025-04-01 17:46:06 +03:00
parent 41d831d29f
commit 68cb3905d1
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -14,7 +14,7 @@
import math
import psycopg2.extras
import psycopg
import requests
from .config import SOLR_SERVER
@ -101,8 +101,8 @@ def index_views(indexType: str, facetField: str):
data.append((id_, views))
# do a batch insert of values from the current "page" of results
sql = f"INSERT INTO {indexType}(id, views) VALUES %s ON CONFLICT(id) DO UPDATE SET views=excluded.views"
psycopg2.extras.execute_values(cursor, sql, data, template="(%s, %s)")
sql = f"INSERT INTO {indexType}(id, views) VALUES (%s, %s) ON CONFLICT(id) DO UPDATE SET views=excluded.views"
cursor.executemany(sql, data)
db.commit()
# clear all items from the list so we can populate it with the next batch
@ -183,8 +183,8 @@ def index_downloads(indexType: str, facetField: str):
data.append((id_, downloads))
# do a batch insert of values from the current "page" of results
sql = f"INSERT INTO {indexType}(id, downloads) VALUES %s ON CONFLICT(id) DO UPDATE SET downloads=excluded.downloads"
psycopg2.extras.execute_values(cursor, sql, data, template="(%s, %s)")
sql = f"INSERT INTO {indexType}(id, downloads) VALUES (%s, %s) ON CONFLICT(id) DO UPDATE SET downloads=excluded.downloads"
cursor.executemany(sql, data)
db.commit()
# clear all items from the list so we can populate it with the next batch