Skip to content

Live per-environment deployment counts - #113

Open
popen2 wants to merge 1 commit into
claude/platz-fix-ws-env-idfrom
claude/platz-env-deployment-counts
Open

popen2 wants to merge 1 commit into
claude/platz-fix-ws-env-idfrom
claude/platz-env-deployment-counts

Conversation

@popen2

@popen2 popen2 commented Jun 14, 2026

Copy link
Copy Markdown
Member

Live per-environment deployment counts

The env list/detail endpoints now return each environment's deployment count, and it stays live — when a deployment is added/removed the count updates wherever an env is shown (switcher, overview, headers), matching Platz's reactive feel — without the frontend loading any deployments.

How

  • Counts, cheaply: EnvWithStats = Env + num_deployments. The count is computed without loading deployments — grouped by cluster in the database and summed per environment (Deployment::count_by_env for the list, count_in_env for detail), scoped to the caller's environments.
  • Live, via env refresh events: a deployment insert/delete (or a move between clusters) changes a count but doesn't touch the envs table, so a new trigger emits a synthetic envs refresh event on the generic db_notifications channel for the affected environment(s). The frontend — which already loads and subscribes to envs — refetches that env and shows the new count. Frequent status/config updates are ignored, so the event only fires when a count actually changes.

Dependency

Stacked on #112 (base branch). The synthetic envs event carries an env_id and relies on #112's wildcard subscription matching to reach the globally-loaded envs collection; the live behavior needs #112 merged first. Once #112 merges, I'll retarget this at main.

The frontend side (read num_deployments, restore the live switcher counts) is in the frontend websocket-scalability PR.

Testing

  • Verified against PostgreSQL that the trigger emits only on count-affecting changes, and for both environments on a cluster move.
  • OpenAPI exposes num_deployments on the env responses (EnvWithStats = allOf [Env, { num_deployments }]), so the SDK picks it up on regen.
  • cargo build / cargo fmt / cargo clippy clean.

https://claude.ai/code/session_019WuF56UqDxdJkYmk4zXD88


Generated by Claude Code

The env list/detail endpoints now return each environment's deployment
count (EnvWithStats = Env + num_deployments), computed without loading the
deployments: counts are grouped by cluster in the database and summed per
environment (Deployment::count_by_env / count_in_env).

To keep the count live, a new trigger emits a synthetic `envs` refresh
event on the generic `db_notifications` channel whenever a deployment
change affects a count -- INSERT, DELETE, or a move between clusters (status
and config updates are ignored). The frontend, which already loads and
subscribes to envs, refetches the affected env and shows the new count.

Stacked on the generic-trigger env_id fix, whose env-tagged events and
wildcard subscription matching are what let the synthetic envs event reach
subscribers.

Verified against PostgreSQL that the trigger emits only on count-affecting
changes (and for both environments on a move), and that the OpenAPI schema
exposes num_deployments on the env responses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants