Skip to content

fix(marketplace): derive template deploy_count from deployment records - #330

Merged
vsilent merged 1 commit into
devfrom
fix/template-deploy-count
Nov 6, 2026
Merged

vsilent merged 1 commit into
devfrom
fix/template-deploy-count

Conversation

@vsilent

@vsilent vsilent commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Bug

Every template reports deploy_count: 0 on GET /api/templates and the storefront, while view_count is live. The counter is only incremented by the marketplace deploy-complete hooks, which never fire from the web pipeline — on dev, stack_template_deployment has 0 rows and all 295 templates show 0 — yet real deployments are recorded as project rows with source_template_id (10 for the floci template alone).

Fix

Compute deploy_count as GREATEST(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). The popular sort 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 .sqlx is byte-identical (verified: cargo sqlx prepare -- --all-targets produced zero tracked diffs).

Tests (stacker-test-pg, per config/docs/TESTING-RULES.md)

  • cargo test --lib → 2311 passed, 0 failed, 6 ignored
  • cargo test --test marketplace_creator_analytics_api → 10 passed (exercises the changed list queries against the DB)
  • cargo test --test marketplace_deploy_complete → 1 passed
  • cargo test --test project_deploy_marketplace_validation → 11 passed
  • cargo test --test project_marketplace_persistence → 2 passed
  • no Skipping tests in the output

cargo clippy -- -D warnings fails on a pre-existing lint in build.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.

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.
@vsilent
vsilent merged commit 0af81d0 into dev Nov 6, 2026
11 checks passed
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.

2 participants