From 94781227b2efe9f847185f841863f78e945c7492 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 22 Dec 2025 12:53:11 +0100 Subject: [PATCH] Fix: Implementeret pagination i vTiger sync for at hente ALLE kunder (batch size 200) --- app/system/backend/sync_router.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/system/backend/sync_router.py b/app/system/backend/sync_router.py index de2cf95..4d46a0b 100644 --- a/app/system/backend/sync_router.py +++ b/app/system/backend/sync_router.py @@ -36,11 +36,29 @@ async def sync_from_vtiger() -> Dict[str, Any]: vtiger = get_vtiger_service() - # Query vTiger for all accounts with CVR or name (no limit to get all) - query = "SELECT id, accountname, email1, siccode, cf_accounts_cvr, website, bill_city, bill_code, bill_country FROM Accounts;" + # Fetch ALL accounts using pagination (vTiger limits to ~200 per request) + all_accounts = [] + offset = 0 + batch_size = 200 - accounts = await vtiger.query(query) - logger.info(f"📥 Fetched {len(accounts)} accounts from vTiger") + while True: + query = f"SELECT id, accountname, email1, siccode, cf_accounts_cvr, website, bill_city, bill_code, bill_country FROM Accounts LIMIT {batch_size} OFFSET {offset};" + batch = await vtiger.query(query) + + if not batch or len(batch) == 0: + break + + all_accounts.extend(batch) + logger.info(f"📥 Fetched batch: {len(batch)} accounts (total so far: {len(all_accounts)})") + + # If we got less than batch_size, we've reached the end + if len(batch) < batch_size: + break + + offset += batch_size + + logger.info(f"📥 Fetched total of {len(all_accounts)} accounts from vTiger") + accounts = all_accounts created_count = 0 updated_count = 0