Skip to content

perf: refactor migrate_to_stripe to use asyncio for concurrent Stripe API calls.#374

Open
vincerevu wants to merge 1 commit intostripe:mainfrom
vincerevu:optimize-init-products-async-5274849350437277779
Open

perf: refactor migrate_to_stripe to use asyncio for concurrent Stripe API calls.#374
vincerevu wants to merge 1 commit intostripe:mainfrom
vincerevu:optimize-init-products-async-5274849350437277779

Conversation

@vincerevu
Copy link
Copy Markdown

What: The script init_products.py now uses asyncio.gather and stripe.*.create_async methods to perform product/price and coupon/promo code creation operations concurrently, rather than sequentially. The results are gathered, and standard output format and local database updating operations are maintained sequentially to ensure stability and compatibility with sqlite.
Why: The original implementation performed API calls sequentially in a loop resulting in an N+1 performance bottleneck heavily gated by network latencies. Parallelizing these external calls significantly speeds up migration.
Measured Improvement: I wrote a test benchmark (benchmark.py) mocking network latencies (0.5s network delay per api call simulating typical conditions) and measured performance across 10 products and 5 coupons. The performance went from ~15s down to ~2s (as expected due to the two parallel execution blocks: 1s max for products/prices, and 1s max for coupons/promos).

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