⚡ Bolt: Caching blueprint variants#52
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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.mdlearning 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.
| if resp.status_code != 200: | ||
| return None |
| @@ -0,0 +1,3 @@ | |||
| ## 2024-05-30 - Printify API N+1 Network Bottleneck | |||
💡 What: Memoized the
get_variantsfunction increate_merch.py,printify_manager.py,merch_factory.py,merg_bridge.py, andcreate_merch_v2.pyutilizing 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.pyto see the improvement in execution speed, especially with repetitive items.PR created automatically by Jules for task 11712490481230770635 started by @merg357