Skip to content

⚡ Bolt: Optimize sync by reducing redundant API calls#118

Merged
abhimehro merged 2 commits intomainfrom
bolt-optimize-api-calls-7523340176869283885
Jan 22, 2026
Merged

⚡ Bolt: Optimize sync by reducing redundant API calls#118
abhimehro merged 2 commits intomainfrom
bolt-optimize-api-calls-7523340176869283885

Conversation

@google-labs-jules
Copy link

⚡ Bolt: Optimize sync by reducing redundant API calls

💡 What:
Maintains a local copy of the folder list (existing_folders) and updates it when folders are deleted. Passes this updated list to get_all_existing_rules to avoid calling list_existing_folders again.

🎯 Why:
The sync_profile function was calling list_existing_folders (API GET) twice:

  1. To check which folders to delete.
  2. Inside get_all_existing_rules to fetch rules.
    By passing the modified state from step 1 to step 2, we save one API call. This improves performance and reduces API load, especially since we already have the knowledge of what was deleted.

📊 Impact:
Reduces API calls by 1 per profile sync (specifically the GET /groups call).

🔬 Measurement:
Verified with a reproduction script that mocks the API client. The call count for list_existing_folders dropped from 2 to 1.
Existing tests passed.


PR created automatically by Jules for task 7523340176869283885 started by @abhimehro

Maintains local state of existing folders during deletion to avoid re-fetching them from the API. This eliminates one API call per profile sync.

- `get_all_existing_rules`: Accepts `known_folders` to skip `list_existing_folders`.
- `sync_profile`: Updates `existing_folders` locally when deleting and passes it to `get_all_existing_rules`.
@google-labs-jules
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@trunk-io
Copy link

trunk-io bot commented Jan 20, 2026

😎 Merged manually by Abhi Mehrotra (@abhimehro) - details.

return {}

def get_all_existing_rules(client: httpx.Client, profile_id: str) -> Set[str]:
def get_all_existing_rules(

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning

Missing function or method docstring

existing_rules = get_all_existing_rules(client, profile_id)
# Optimization: Pass the updated existing_folders to avoid redundant API call
existing_rules = get_all_existing_rules(client, profile_id, known_folders=existing_folders)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (103/100) Warning

Line too long (103/100)
return {}

def get_all_existing_rules(client: httpx.Client, profile_id: str) -> Set[str]:
def get_all_existing_rules(

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring
def get_all_existing_rules(
client: httpx.Client,
profile_id: str,
known_folders: Optional[Dict[str, str]] = None

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation before block (add 4 spaces). Warning

Wrong hanging indentation before block (add 4 spaces).
main.py Outdated

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (103/100) Warning

Line too long (103/100)
@abhimehro abhimehro marked this pull request as ready for review January 21, 2026 18:40
Copilot AI review requested due to automatic review settings January 21, 2026 18:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the sync_profile function by reducing redundant API calls through local state management. When folders are deleted, the local existing_folders dictionary is updated and reused instead of making another API call to list folders.

Changes:

  • Added optional known_folders parameter to get_all_existing_rules to accept pre-fetched folder data
  • Modified folder deletion logic to track successful deletions in local state
  • Documented the optimization pattern in bolt.md

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
main.py Added known_folders parameter to get_all_existing_rules and updated sync_profile to maintain local folder state during deletions, eliminating one redundant API call per sync
.jules/bolt.md Documented the "Read -> Modify -> Read" to "Read -> Modify (update local) -> Use local" optimization pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +358 to +362
def get_all_existing_rules(
client: httpx.Client,
profile_id: str,
known_folders: Optional[Dict[str, str]] = None
) -> Set[str]:
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new optional parameter known_folders lacks test coverage. While there is an existing test for get_all_existing_rules in test_main.py, it doesn't verify the behavior when known_folders is provided. Consider adding a test case that:

  1. Passes a pre-populated known_folders dictionary
  2. Verifies that list_existing_folders is NOT called when known_folders is provided
  3. Confirms that the provided folders are used to fetch rules

Copilot uses AI. Check for mistakes.
Comment on lines +760 to +764
# Optimization: Maintain local state of folders to avoid re-fetching
# delete_folder returns True on success
if delete_folder(client, profile_id, name, existing_folders[name]):
del existing_folders[name]
deletion_occurred = True
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for maintaining local folder state during deletion lacks test coverage. This critical optimization should be tested to verify:

  1. delete_folder is called with correct parameters
  2. Only successfully deleted folders are removed from existing_folders
  3. Failed deletions leave the folder in existing_folders
  4. The updated existing_folders is correctly passed to get_all_existing_rules

Since test_main.py contains comprehensive tests for other functions, consider adding a test for this deletion tracking behavior.

Copilot uses AI. Check for mistakes.
@abhimehro
Copy link
Owner

Hi @google-lab-jules, please open a new pull request to apply any changes based on the comments in this thread. Thanks!

@google-labs-jules
Copy link
Author

Hi @google-lab-jules, please open a new pull request to apply any changes based on the comments in this thread. Thanks!

Understood. I will open a new pull request with the changes.

Maintains local state of existing folders during deletion to avoid re-fetching them from the API. This eliminates one API call per profile sync.

- `get_all_existing_rules`: Accepts `known_folders` to skip `list_existing_folders`.
- `sync_profile`: Updates `existing_folders` locally when deleting and passes it to `get_all_existing_rules`.
return {}

def get_all_existing_rules(client: httpx.Client, profile_id: str) -> Set[str]:
def get_all_existing_rules(

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation before block (add 4 spaces). Warning

Wrong hanging indentation before block (add 4 spaces).
@abhimehro abhimehro merged commit 42ca056 into main Jan 22, 2026
18 checks passed
@abhimehro abhimehro deleted the bolt-optimize-api-calls-7523340176869283885 branch January 22, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants