Repository navigation
feat: trigger prompt volume analysis after checkout - #582
Conversation
Signed-off-by: Bharadwaj <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks — the shared volume-analysis.js extraction and the internal endpoint shape (CRON_SECRET + detached 202) are exactly right. Two things need fixing before this can land:
1. /analyze-batch no longer respects the caller's selection. The old endpoint analyzed the specific prompts array from the request body (the subset the user ticked in the Analyze dialog). The refactor resolves the brand from the first prompt and calls analyzeBrandVolumes(brandId), which analyzes every prompt in the brand:
- Selecting 3 prompts on a 200-prompt brand now runs 200 serial LLM + DataForSEO calls inside one awaited request (cost + almost certain timeout).
volume_usagegets recorded for all analyzed prompts, not the user's selection.- The web client still sends
locationCode/languageCode/force(web/src/lib/actions/volumes.ts→analyzePromptVolumesBatch), and the location/language overrides are now silently dropped.
Suggestion: give analyzeBrandVolumes optional { promptIds, locationCode, languageCode } and pass the request's subset + overrides through from /analyze-batch, keeping its old contract intact.
2. The auto-trigger isn't idempotent. The Stripe success route runs on every visit with a session_id (its only guard is payment_status === 'paid'), so a refresh of the success page re-fires the analysis — cached intents are reused, but fetchAndSaveVolumes still re-hits DataForSEO for every prompt. Add an onlyMissing: true mode for the internal path that skips prompts which already have a prompt_volumes row: the first post-checkout call analyzes everything (all prompts are new), and any repeat call becomes a no-op.
Minor: the two import lines from ../lib/volume-analysis.js in routes/volumes.js can be merged into one.
CI is green and the rest reads well — happy to approve once these two are in.
gkhngyk
left a comment
There was a problem hiding this comment.
Both requested changes are addressed — analyze-batch now scopes to the selected prompt IDs, and the post-checkout trigger is idempotent via onlyMissing. Thanks for the quick turnaround!
Summary
This PR automatically triggers prompt volume analysis after a successful Stripe checkout, so new users don't have to manually click Analyze prompts before seeing Volume and Competition data.
Changes
server/src/lib/volume-analysis.js./api/volumes/analyze-batchendpoint to reuse the shared implementation.POST /api/internal/analyze-volumessecured withCRON_SECRETauthentication.202 Accepted.Related issue
Closes #541
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsChecklist
feature/,fix/,chore/,docs/)yarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)