mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-04-16 03:29:24 +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:
parent
41d831d29f
commit
68cb3905d1
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import psycopg2.extras
|
import psycopg
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from .config import SOLR_SERVER
|
from .config import SOLR_SERVER
|
||||||
@ -101,8 +101,8 @@ def index_views(indexType: str, facetField: str):
|
|||||||
data.append((id_, views))
|
data.append((id_, views))
|
||||||
|
|
||||||
# do a batch insert of values from the current "page" of results
|
# 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"
|
sql = f"INSERT INTO {indexType}(id, views) VALUES (%s, %s) ON CONFLICT(id) DO UPDATE SET views=excluded.views"
|
||||||
psycopg2.extras.execute_values(cursor, sql, data, template="(%s, %s)")
|
cursor.executemany(sql, data)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# clear all items from the list so we can populate it with the next batch
|
# 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))
|
data.append((id_, downloads))
|
||||||
|
|
||||||
# do a batch insert of values from the current "page" of results
|
# 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"
|
sql = f"INSERT INTO {indexType}(id, downloads) VALUES (%s, %s) ON CONFLICT(id) DO UPDATE SET downloads=excluded.downloads"
|
||||||
psycopg2.extras.execute_values(cursor, sql, data, template="(%s, %s)")
|
cursor.executemany(sql, data)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# clear all items from the list so we can populate it with the next batch
|
# clear all items from the list so we can populate it with the next batch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user