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'):