From d2e54009e0268e54653e38fcce699e106c61ccd5 Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:22:09 -0700 Subject: [PATCH] Auto-update: Tue Jul 30 15:22:09 PDT 2024 --- sijapi/classes.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sijapi/classes.py b/sijapi/classes.py index a682aa0..f8d364a 100644 --- a/sijapi/classes.py +++ b/sijapi/classes.py @@ -655,12 +655,13 @@ class APIConfig(BaseModel): {', '.join(f"{col} = EXCLUDED.{col}" for col in columns if col != 'id')} """ - # Execute the insert for each change - affected_rows = 0 - for change in changes: - values = [change[col] for col in columns] - result = await conn.execute(insert_query, *values) - affected_rows += int(result.split()[-1]) + # Execute the insert for all changes in a single transaction + async with conn.transaction(): + affected_rows = 0 + for change in changes: + values = [change[col] for col in columns] + result = await conn.execute(insert_query, *values) + affected_rows += int(result.split()[-1]) return affected_rows @@ -670,6 +671,7 @@ class APIConfig(BaseModel): return 0 + async def push_changes_to_all(self): for pool_entry in self.POOL: if pool_entry['ts_id'] != os.environ.get('TS_ID'):