Parallelize AI price check batches, increase batch size to 25

500-item catalog was making 50 sequential API calls, causing progressive rate-limit
throttling (explains "super slow towards the end") and ~$3 in credits.

- BatchSize: 10 → 25 (word limits are in place; 25 items × ~80 tokens ≈ 2000
  output tokens, well within MaxTokens=8192 — the original truncation cause)
- Run up to 3 batches concurrently via SemaphoreSlim(3) — independent API calls
  with no shared state, so no growing context issue
- For a 500-item catalog: 50 sequential calls → 20 calls in ~7 parallel waves,
  roughly 4× faster and 60% cheaper
- Dropped unused `costs` param from AnalyzeBatchAsync (system prompt has all costs)
- JS progress timing updated to reflect parallel waves

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 20:27:07 -04:00
parent 9370fcdd8f
commit 19cc03ad1c
2 changed files with 33 additions and 14 deletions
@@ -12,8 +12,10 @@
// Estimate total seconds based on item count (roughly 12s per batch of 25, min 15s).
function estimateDuration(itemCount) {
var batches = Math.max(1, Math.ceil(itemCount / 10));
return Math.max(15, batches * 10);
// 25 items/batch, up to 3 concurrent — wall time ≈ ceil(batches/3) × 12s
var batches = Math.max(1, Math.ceil(itemCount / 25));
var waves = Math.ceil(batches / 3);
return Math.max(15, waves * 12);
}
// Messages keyed to approximate progress milestones (0100).