Skip to content

⚡ Bolt: Caching blueprint variants#52

Open
merg357 wants to merge 1 commit into
mainfrom
bolt-optimize-variants-fetch-11712490481230770635
Open

⚡ Bolt: Caching blueprint variants#52
merg357 wants to merge 1 commit into
mainfrom
bolt-optimize-variants-fetch-11712490481230770635

Conversation

@merg357

@merg357 merg357 commented May 30, 2026

Copy link
Copy Markdown
Owner

💡 What: Memoized the get_variants function in create_merch.py, printify_manager.py, merch_factory.py, merg_bridge.py, and create_merch_v2.py utilizing Python's @functools.lru_cache. Converted list return types to tuples to prevent unintended side effects on cached objects. Updated the type hints accordingly.
🎯 Why: Iteratively creating products inside loops previously resulted in N+1 duplicated network requests to fetch the variants for the same blueprints.
📊 Impact: Considerably cuts down the amount of requests sent to the Printify API during bulk execution loops, noticeably lowering total completion time, lowering I/O blocks, and preventing API rate-limits.
🔬 Measurement: Verify with time python3 create_merch.py to see the improvement in execution speed, especially with repetitive items.


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

Memoized the Printify variants fetch API call using `functools.lru_cache` returning an immutable tuple across `create_merch.py`, `printify_manager.py`, `merch_factory.py`, `merg_bridge.py`, and `create_merch_v2.py`. This prevents redundant API requests within loops.

Co-authored-by: merg357 <221854052+merg357@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 30, 2026 09:27
@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

This PR improves Printify bulk product creation scripts by memoizing blueprint variant lookups to reduce repeated Printify catalog API calls during loops.

Changes:

  • Added functools.lru_cache(maxsize=None) to variant-fetching helpers across product creation scripts.
  • Converted cached variant return values from lists to tuples and updated related type hints.
  • Added a .jules/bolt.md learning note documenting the N+1 API bottleneck.

Reviewed changes

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

Show a summary per file
File Description
printify_manager.py Caches variant ID lookups for manager-driven product creation.
merg_bridge.py Caches blueprint variant payloads returned from the catalog endpoint.
merch_factory.py Caches variant ID lookups used by factory product creation.
create_merch.py Caches default-provider variant ID lookups for bulk creation.
create_merch_v2.py Adds cached variant lookup helper used by the main creation loop.
.jules/bolt.md Documents the caching optimization as a project learning.

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

Comment thread create_merch_v2.py
Comment on lines +39 to +40
if resp.status_code != 200:
return None
Comment thread .jules/bolt.md
@@ -0,0 +1,3 @@
## 2024-05-30 - Printify API N+1 Network Bottleneck
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