From 8f9097d0acb3ef0e8d534752a4064d4612afe89b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 13 Jan 2026 15:03:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Remove=20redundant=20API=20?= =?UTF-8?q?call=20to=20list=20folders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored `get_all_existing_rules` to accept `existing_folders_map`. Updated `sync_profile` to maintain and pass the local folder state instead of re-fetching it. This reduces the number of API calls per profile sync by 1. --- main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index e6aabc57..56755a2e 100644 --- a/main.py +++ b/main.py @@ -325,7 +325,11 @@ def list_existing_folders(client: httpx.Client, profile_id: str) -> Dict[str, st log.error(f"Failed to list existing folders: {sanitize_for_log(e)}") return {} -def get_all_existing_rules(client: httpx.Client, profile_id: str) -> Set[str]: +def get_all_existing_rules( + client: httpx.Client, + profile_id: str, + existing_folders_map: Optional[Dict[str, str]] = None, +) -> Set[str]: all_rules = set() all_rules_lock = threading.Lock() @@ -356,7 +360,10 @@ def _fetch_folder_rules(folder_id: str): pass # Get rules from folders in parallel - folders = list_existing_folders(client, profile_id) + if existing_folders_map is not None: + folders = existing_folders_map + else: + folders = list_existing_folders(client, profile_id) # Parallelize fetching rules from folders. # Using 5 workers to be safe with rate limits, though GETs are usually cheaper. @@ -649,8 +656,9 @@ def sync_profile( for folder_data in folder_data_list: name = folder_data["group"]["group"].strip() if name in existing_folders: - delete_folder(client, profile_id, name, existing_folders[name]) - deletion_occurred = True + if delete_folder(client, profile_id, name, existing_folders[name]): + del existing_folders[name] + deletion_occurred = True # CRITICAL FIX: Increased wait time for massive folders to clear if deletion_occurred: @@ -658,7 +666,7 @@ def sync_profile( log.info("Waiting 60s for deletions to propagate (prevents 'Badware Hoster' zombie state)...") countdown_timer(60, "Waiting for deletions to propagate") - existing_rules = get_all_existing_rules(client, profile_id) + existing_rules = get_all_existing_rules(client, profile_id, existing_folders) with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: future_to_folder = {