Repository navigation
fix(marketplace): derive template deploy_count from deployment records - #330
Merged
Merged
Conversation
stack_template.deploy_count was 0 for every template on /api/templates and the storefront: the counter is only incremented by the marketplace deploy-complete hooks, which never fire from the web pipeline (the stack_template_deployment event table is empty and the counter untouched), while real deployments are recorded as project rows with source_template_id. Compute deploy_count as GREATEST of the stored counter, the number of project records with source_template_id, and the number of verified stack_template_deployment events. Existing deployments are counted immediately and future ones keep counting even when a hook is missed. The 'popular' sort now orders by the derived value instead of the stale counter. All queries are runtime query_as, so no .sqlx data changes.
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.
Bug
Every template reports
deploy_count: 0onGET /api/templatesand the storefront, whileview_countis live. The counter is only incremented by the marketplace deploy-complete hooks, which never fire from the web pipeline — on dev,stack_template_deploymenthas 0 rows and all 295 templates show 0 — yet real deployments are recorded asprojectrows withsource_template_id(10 for theflocitemplate alone).Fix
Compute
deploy_countasGREATEST(stored counter, COUNT(project WHERE source_template_id = t.id), COUNT(stack_template_deployment WHERE template_id = t.id))in the template queries (public list/detail, per-creator list, admin lookups). Existing deployments are counted immediately, future ones keep counting even when a hook is missed, and the three sources never double-count (GREATEST, not SUM). Thepopularsort now orders by the derived value instead of the stale counter.All touched queries are runtime
query_as— no compile-time-checked query changed, so.sqlxis byte-identical (verified:cargo sqlx prepare -- --all-targetsproduced zero tracked diffs).Tests (stacker-test-pg, per config/docs/TESTING-RULES.md)
cargo test --lib→ 2311 passed, 0 failed, 6 ignoredcargo test --test marketplace_creator_analytics_api→ 10 passed (exercises the changed list queries against the DB)cargo test --test marketplace_deploy_complete→ 1 passedcargo test --test project_deploy_marketplace_validation→ 11 passedcargo test --test project_marketplace_persistence→ 2 passedSkipping testsin the outputcargo clippy -- -D warningsfails on a pre-existing lint inbuild.rs:37(clippy::useless_conversion, local clippy 1.94 toolchain) — untouched by this diff.Sibling PRs: trydirect/user#200 (storefront count source), blog fix reads the value.