Skip to content

perf(scheduler): collapse empty-run bump to single RETURNING query - #991

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
perf/scheduler-returning-clause
Apr 19, 2026
Merged

HongmingWang-Rabbit merged 1 commit into
stagingfrom
perf/scheduler-returning-clause

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

Phantom-producer detector (#795) was doing `UPDATE` + `SELECT` in two roundtrips — first incrementing `consecutive_empty_runs`, then re-reading to check the stale threshold. Switch to `UPDATE ... RETURNING` so the post-increment value comes back in one query.

Called once per schedule per cron tick. At 100 tenants × dozens of schedules per tenant the halved DB traffic is measurable.

Side benefit: now properly logs if the bump itself fails (previously silent-swallowed the error and still ran the SELECT).

Test plan

  • `go test ./internal/scheduler/...` passes

🤖 Generated with Claude Code

The phantom-producer detector (#795) was doing UPDATE + SELECT in two
roundtrips — first incrementing consecutive_empty_runs, then re-
reading to check the stale threshold. Switch to UPDATE ... RETURNING
so the post-increment value comes back in one query.

Called once per schedule per cron tick. At 100 tenants × dozens of
schedules per tenant, the halved DB traffic on the empty-response
path is measurable, not just cosmetic.

Also now properly logs if the bump itself fails (previously it silent-
swallowed the ExecContext error and still ran the SELECT, which would
confuse debugging).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit merged commit 2c5cac5 into staging Apr 19, 2026
9 checks passed
molecule-ai Bot pushed a commit that referenced this pull request Apr 21, 2026
perf(scheduler): collapse empty-run bump to single RETURNING query
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the perf/scheduler-returning-clause branch April 24, 2026 00:12
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.

1 participant