Skip to content

⚡ Bolt: [performance improvement] Cache static Printify variant lookups#48

Open
merg357 wants to merge 1 commit into
mainfrom
bolt-perf-optimization-lru-cache-2441362908905101839
Open

⚡ Bolt: [performance improvement] Cache static Printify variant lookups#48
merg357 wants to merge 1 commit into
mainfrom
bolt-perf-optimization-lru-cache-2441362908905101839

Conversation

@merg357

@merg357 merg357 commented May 26, 2026

Copy link
Copy Markdown
Owner

💡 What: Added @functools.lru_cache(maxsize=None) to Printify variant lookup functions across the codebase (get_variants, get_blueprint_variants) and changed their return types to immutable tuples to guarantee thread safety and prevent downstream modification.

🎯 Why: To eliminate N+1 network requests. When bulk-creating products, the same static/infrequently changing print provider variant data is queried repeatedly, causing a significant network bottleneck.

📊 Impact: Drastically reduces total execution time and network I/O during bulk product creation by skipping redundant API calls. Also avoids API rate limits.

🔬 Measurement: Verify by running product creation commands for multiple products targeting the same blueprint/provider combination. Network inspection (or timing the script execution) will show only one request to the /variants.json endpoint per unique blueprint/provider.


PR created automatically by Jules for task 2441362908905101839 started by @merg357

Added `@functools.lru_cache(maxsize=None)` to `get_variants` and `get_blueprint_variants` functions in `printify_manager.py`, `create_merch.py`, `merch_factory.py`, and `merg_bridge.py`.

Converted the returned list to an immutable tuple to prevent downstream state mutations.

Added journal entry for learning about immutable caching with lru_cache.

Co-authored-by: merg357 <221854052+merg357@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 26, 2026 09:10
@google-labs-jules

Copy link
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds @functools.lru_cache(maxsize=None) to Printify variant lookup functions to eliminate redundant API calls during bulk product creation, and converts return types from list to immutable tuple for cache safety.

Changes:

  • Memoize get_variants/get_blueprint_variants with functools.lru_cache in 3 product-creation scripts.
  • Change return types from list to tuple (immutable) to protect cached values.
  • Add a .jules/bolt.md learning note documenting the pattern.

Reviewed changes

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

Show a summary per file
File Description
printify_manager.py Adds lru_cache + tuple return to get_variants.
merg_bridge.py Adds lru_cache + tuple return to get_blueprint_variants (still contains mutable dicts).
merch_factory.py Adds lru_cache + tuple return to get_variants; caller signature still typed list.
create_merch.py Adds lru_cache + Tuple return to get_variants.
.jules/bolt.md New documentation note on immutable lru_cache pattern.

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

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.

2 participants