perf(warehouse): D — prefetch Shopify variant theo lô cho create-sale (~10× nhanh hơn)#255
Open
ecommeanblvd wants to merge 1 commit into
Open
perf(warehouse): D — prefetch Shopify variant theo lô cho create-sale (~10× nhanh hơn)#255ecommeanblvd wants to merge 1 commit into
ecommeanblvd wants to merge 1 commit into
Conversation
Vòng đánh giá cũ query Shopify 2 lần/SKU (base + base-Sale) + sleep → ~2·N round-trip cho 504 SKU (~8 phút). Gộp thành prefetch theo lô (sku:'a' OR sku:'b'…, 25 term/query) 1 lần, bucket theo SKU (UPPERCASE), rồi evaluateSku tra map in-memory (thuần, không I/O). Dry-run production: 47s (từ ~8 phút), 0 lỗi, tally y hệt bản cũ (ACTIVE 211 / not-found 185 / -Sale 86 / DRAFT 16 / customize 5 / mean 1). - create-sale-logic.ts: thêm chunk() + bucketBySku() (thuần, có test) - create-sale.ts: VARIANT_FIELDS fragment dùng chung; prefetchVariantsBySku; evaluateSku → sync tra map; recheck trước khi ghi vẫn live (an toàn race) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vì sao
Engine C (
create-sale.ts) đánh giá từng SKU bằng 2 query Shopify + 2 sleep (base + base-Sale) → ~2·N round-trip cho 504 SKU, dry-run/cron mất ~8 phút.Thay đổi
(base, base-Sale)thành querysku:'a' OR sku:'b' …(25 term/query), chạy 1 lần, bucket kết quả theo SKU (UPPERCASE) vàoMap.evaluateSkugiờ thuần (sync), travariantMapin-memory — không I/O trong vòng lặp.VARIANT_FIELDSfragment dùng chung cho query đơn + query lô (không lặp field).${base}-Sale(chống race giữa evaluate ↔ write) — chỉ chạy cho nhóm thực sự tạo.chunk(),bucketBySku().Kiểm chứng
tsc --noEmit: 0 lỗi ·vitestcreate-sale-logic: 27/27 pass · eslint: cleanACTIVE 211 · not-found 185 · -Sale 86 · DRAFT 16 · customize 5 · mean 1 · eligible 0Behavior-preserving thuần tối ưu tốc độ — không đổi quyết định tạo/skip.
🤖 Generated with Claude Code