From 68cb3905d1b499a5c3970bcd322c45d1a88519fe Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 1 Apr 2025 17:46:06 +0300 Subject: [PATCH] dspace_statistics_api/indexer.py: don't use psycopg2.extras.execute_values() In psycopg version 3 we can use cursor.executemany(). --- dspace_statistics_api/indexer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dspace_statistics_api/indexer.py b/dspace_statistics_api/indexer.py index 99d8072..16fb0d9 100644 --- a/dspace_statistics_api/indexer.py +++ b/dspace_statistics_api/indexer.py @@ -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