Skip to content

⚡ Optimize folder lookups with in-memory caching#3

Draft
yj9404 wants to merge 1 commit intomainfrom
performance-optimize-folder-lookups-11118709063343959285
Draft

⚡ Optimize folder lookups with in-memory caching#3
yj9404 wants to merge 1 commit intomainfrom
performance-optimize-folder-lookups-11118709063343959285

Conversation

@yj9404
Copy link
Copy Markdown
Owner

@yj9404 yj9404 commented Apr 6, 2026

This PR implements in-memory caching for folder lookups in create_worklog.py to reduce redundant API calls to Confluence.

💡 What:

  • Introduced a module-level _FOLDER_CACHE dictionary to store folder lists for each parent_id.
  • Modified get_folder_id_by_name to prioritize cache lookups and populate the cache on the first fetch.
  • Updated find_or_create_folder to append newly created folders to the cache, ensuring consistency without additional API calls.

🎯 Why:

The script frequently checks for the existence of folders (Year, Month) that it might have already looked up or created earlier in the same execution. Caching these results eliminates unnecessary GET requests and potentially redundant POST attempts if the lookup failed but a previous create succeeded.

📊 Measured Improvement:

Using a benchmark script that simulates a run for December 30, 2025 (which involves checking current year/month, next year/month, and Thursday's year/month folders), the following improvements were observed:

  • GET calls: Reduced from 7 to 2 (71.4% improvement).
  • POST calls: Reduced from 8 to 5 (37.5% improvement).
  • Execution Time: Slightly reduced due to fewer network simulations (0.0085s to 0.0055s in a mock environment).

All existing tests in test_create_worklog.py have been updated to account for the caching behavior and pass successfully.


PR created automatically by Jules for task 11118709063343959285 started by @yj9404

- Added `_FOLDER_CACHE` dictionary to `create_worklog.py`.
- Updated `get_folder_id_by_name` to check and populate the cache.
- Updated `find_or_create_folder` to update the cache when a new folder is created.
- Updated `test_create_worklog.py` to reset the cache between tests and handle the mocked `requests` environment more robustly.

Performance impact:
Measured a reduction in API calls for a standard execution:
- GET calls: 7 -> 2
- POST calls: 8 -> 5
(Baseline established on a mock run for Dec 30, 2025)

Co-authored-by: yj9404 <47413412+yj9404@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant