Skip to content

perf(db): query fingerprint metrics and home page query optimization#577

Merged
tompscanlan merged 1 commit into
mainfrom
feature/db-query-performance
Apr 13, 2026
Merged

perf(db): query fingerprint metrics and home page query optimization#577
tompscanlan merged 1 commit into
mainfrom
feature/db-query-performance

Conversation

@tompscanlan
Copy link
Copy Markdown
Contributor

Summary

  • Add query fingerprint label to db_query_duration_seconds Prometheus histogram — enables identifying which specific SQL query shapes are slow (fingerprint already computed, just threaded to metric label)
  • Add skipCount option to ContrailQueryService.find() — guest home page skips the redundant COUNT(*) full table scan since it only random-samples 4 events from 50
  • Replace ORDER BY RANDOM() in getHomePageFeaturedGroups with a two-query ID-then-fetch pattern — avoids full table sort with JOINs

Addresses consistent 500ms p99 SELECT query duration in production (confirmed via Prometheus: p95=432ms, p99=486ms on SELECT operations).

Relates to: om-otp8, om-kcmj

Test plan

  • database-metrics.service.spec.ts — 4 new tests for fingerprint label
  • contrail-query.service.spec.ts — 3 new tests for skipCount option
  • event-query.service.spec.ts — 1 new test for skipCount passthrough
  • group.service.spec.ts — 2 new tests for two-query featured groups pattern
  • Deploy to dev and verify p99 drops in Prometheus dashboard
  • Check Prometheus for fingerprint label populating on db_query_duration_seconds

…me page queries

- Add fingerprint label to db_query_duration_seconds histogram for identifying slow query shapes
- Add skipCount option to ContrailQueryService.find() to avoid unnecessary COUNT(*) scans
- Replace ORDER BY RANDOM() in getHomePageFeaturedGroups with two-query ID-then-fetch pattern

Addresses consistent 500ms p99 SELECT query duration in production.
@tompscanlan tompscanlan merged commit debfc9a into main Apr 13, 2026
4 checks passed
tompscanlan added a commit that referenced this pull request Apr 23, 2026
* revert: remove unreleased features from main, align with prod (v1.5.1)

Reverts unreleased features to bring main back in sync with production:

- #577 perf(db): query fingerprint + home page optimization
- #576 feat: unified AttendanceService
- #574 feat(contrail): integrate Contrail appview

Hotfix changes (v1.5.1) are retained — they exist in the baseline.

All work is preserved on its respective feature branch:
- feature/contrail-integration
- feature/attendance-service
- feature/db-query-performance
- feature/contrail-rsvp

Direction shift: adopting Contrail/atmo as the new stack rather than
integrating Contrail into the OpenMeet API.

* fix(test): use future dates in edge-cases spec to avoid past-event guard

The hotfix (v1.5.1) added a past-event RSVP guard that rejects RSVPs
to events with past start dates. The edge-cases spec used 2024 dates,
hitting the guard before reaching the race condition logic under test.
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