From 57a650b73aa4ed0f43f6bb79218132bec4968fc3 Mon Sep 17 00:00:00 2001
From: sanj <67624670+iodrift@users.noreply.github.com>
Date: Tue, 30 Jul 2024 16:55:13 -0700
Subject: [PATCH] Auto-update: Tue Jul 30 16:55:13 PDT 2024

---
 sijapi/classes.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sijapi/classes.py b/sijapi/classes.py
index f82794c..f2cc19c 100644
--- a/sijapi/classes.py
+++ b/sijapi/classes.py
@@ -721,11 +721,12 @@ class APIConfig(BaseModel):
             stmt = await conn.prepare(insert_query)
 
             affected_rows = 0
-            for change in tqdm(changes, desc=f"Syncing {table_name}", unit="row"):
-                values = [change[col] for col in columns]
-                debug(f"Executing query for {table_name} with values: {values}")
-                result = await stmt.execute(*values)
-                affected_rows += 1  # Since we're executing one at a time, each successful execution affects one row
+            values_list = [[change[col] for col in columns] for change in changes]
+            
+            # Use executemany for batch insert
+            result = await stmt.executemany(values_list)
+            affected_rows = result.split()[-1] if result else 0
+            affected_rows = int(affected_rows) if affected_rows.isdigit() else 0
 
             return affected_rows
 
@@ -737,6 +738,7 @@ class APIConfig(BaseModel):
 
 
 
+
     async def sync_spatial_ref_sys(self, source_conn, dest_conn):
         try:
             # Get all entries from the source