Skip to content

perf(db): rate-limit upsert, image index, rag alias warmup - #1547

Merged
BigSimmo merged 3 commits into
mainfrom
cursor/db-query-perf-eb0f
Jul 31, 2026
Merged

perf(db): rate-limit upsert, image index, rag alias warmup#1547
BigSimmo merged 3 commits into
mainfrom
cursor/db-query-perf-eb0f

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Rewrite consume_api_subject_rate_limit / consume_api_rate_limit to a single INSERT … ON CONFLICT upsert (hosted apply still needs explicit approval).
  • Add partial composite index document_images_searchable_doc_page_relevance_idx for the hydration filter/order pattern.
  • Warm rag_aliases at production boot via instrumentation.register(), and raise the in-memory TTL from 60s to 300s.
  • App-layer: short durable deny cache for already-limited subjects only — never cache allow decisions (avoids multi-instance under-count). Rejected fire-and-forget rate limiting.
  • Sentry Metric Alert for p95(span.duration) / span.op:db > 500ms could not be created from this environment (no Sentry UI session / create-alert MCP tool). Manual step documented below.

RAG impact: no retrieval behaviour change — alias cache TTL/warmup and hydration index only; ranking/selection/comparator paths untouched.

Verification

  • npm run verify:pr-local (lint, typecheck, full unit suite, production build, client-bundle scan, offline RAG fixtures — passed)
  • Focused suite for touched sources: 848 passed
  • tests/api-rate-limit-fallback.test.ts, tests/rag-alias-cache-warmup.test.ts, tests/supabase-schema.test.ts — 92 passed
  • npm run check:migration-role
  • Verification not run: full Docker npm run drift:manifest (containerd overlay mount failure in this VM); schema_sha256 updated offline — regenerate snapshot when Docker works
  • UI verification not run: no UI/routing/styling change
  • Sentry metric alert not created: login wall / no create-metric-alert MCP tool

Risk and rollout

  • Risk: Rate-limit function rewrite must preserve bucket accounting; deny-cache only accelerates already-limited subjects. Index is additive. Alias cache warm is best-effort and non-blocking.
  • Rollback: revert migration/app commit; drop new index if needed; restore prior function bodies from previous migration.
  • Provider or production effects: Hosted Supabase migration not applied in this PR — requires explicit operator approval after merge.

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

Manual Sentry alert (blocked here):

  1. Monitors → Alerts → Create Alert → Metric Alert
  2. Metric: p95(span.duration), filter span.op:db, environment production
  3. Threshold: alert if > 500ms
  4. Notify Active Members / issue owners

After merge, apply supabase/migrations/20260731150000_db_query_perf_rate_limit_and_image_indexes.sql to hosted Supabase with explicit approval, then npm run drift:manifest.

Open in Web Open in Cursor 

Rewrite consume_api_*_rate_limit to upsert, add a searchable
document_images composite index, warm rag_aliases at boot with a
longer TTL, and cache durable rate-limit denials only (never allows).
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 5 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 38dbbf17-c91d-47db-b30d-c8373c17013f

📥 Commits

Reviewing files that changed from the base of the PR and between 58aeee6 and 6af0412.

📒 Files selected for processing (9)
  • src/instrumentation.ts
  • src/lib/api-rate-limit.ts
  • src/lib/rag/rag-retrieval-variants.ts
  • supabase/drift-manifest.json
  • supabase/migrations/20260731150000_db_query_perf_rate_limit_and_image_indexes.sql
  • supabase/schema.sql
  • tests/api-rate-limit-fallback.test.ts
  • tests/rag-alias-cache-warmup.test.ts
  • tests/supabase-schema.test.ts

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 31, 2026

Copy link
Copy Markdown

Updates to Preview Branch (cursor/db-query-perf-eb0f) ↗︎

Deployments Status Updated
Database Fri, 31 Jul 2026 15:44:34 UTC
Services Fri, 31 Jul 2026 15:44:34 UTC
APIs Fri, 31 Jul 2026 15:44:34 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Fri, 31 Jul 2026 15:44:36 UTC
Migrations Fri, 31 Jul 2026 15:44:38 UTC
Seeding Fri, 31 Jul 2026 15:44:39 UTC
Edge Functions Fri, 31 Jul 2026 15:44:40 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@ecc-tools

ecc-tools Bot commented Jul 31, 2026

Copy link
Copy Markdown

🔒 Upgrade Required

Private repository analysis requires Pro or Enterprise.

Upgrade: https://ecc.tools/pricing?plan=pro


ECC Tools keeps the core app open, and puts private repos, team features, and enterprise controls behind paid tiers.

@BigSimmo
BigSimmo marked this pull request as ready for review July 31, 2026 15:21
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@ecc-tools

ecc-tools Bot commented Jul 31, 2026

Copy link
Copy Markdown

🔒 Upgrade Required

Private repository analysis requires Pro or Enterprise.

Upgrade: https://ecc.tools/pricing?plan=pro


ECC Tools keeps the core app open, and puts private repos, team features, and enterprise controls behind paid tiers.

@ecc-tools

ecc-tools Bot commented Jul 31, 2026

Copy link
Copy Markdown

🔒 Upgrade Required

Private repository analysis requires Pro or Enterprise.

Upgrade: https://ecc.tools/pricing?plan=pro


ECC Tools keeps the core app open, and puts private repos, team features, and enterprise controls behind paid tiers.

@BigSimmo
BigSimmo enabled auto-merge (squash) July 31, 2026 15:44
@BigSimmo
BigSimmo merged commit 4853d64 into main Jul 31, 2026
24 checks passed
@BigSimmo
BigSimmo deleted the cursor/db-query-perf-eb0f branch July 31, 2026 15:50
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