Skip to content

perf(db): fix #245 add brin index on contract_events and endpoint - #778

Open
fhayvy wants to merge 2 commits into
vjuliaife:mainfrom
fhayvy:feature/brin-index-245
Open

perf(db): fix #245 add brin index on contract_events and endpoint#778
fhayvy wants to merge 2 commits into
vjuliaife:mainfrom
fhayvy:feature/brin-index-245

Conversation

@fhayvy

@fhayvy fhayvy commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Closes #245

Addes a BRIN (Block Range INdex) index on the contract_events table's created_at column, and implementing a corresponding Express REST API endpoint GET /importers/admin/events to query events in a time range with pagination.

Rationale & Flow:

  • BRIN Index: We index contract_events.created_at using BRIN with pages_per_range = 32. Since event data is written in roughly chronological order, the values of created_at are highly correlated with their physical location in the table. BRIN indices are extremely small (~1:800 or 99.8% smaller than a B-Tree index), saving valuable memory and disk space under high ingestion volumes.
  • Monthly Partitioning compatibility: Because PostgreSQL propagates indices from parent tables to child partitions automatically, this index is fully compatible with the monthly partitioned table strategy.
  • Admin REST endpoint: Added GET /importers/admin/events which accepts from (ISO 8601), to (ISO 8601), limit (max 500), and offset parameters, validating them using Zod. The endpoint is secured so only users with the surety_admin role can access it, querying database events filtered by the date range using the BRIN index.
  • Type Safety & Compilation: Resolved pre-existing compilation blockers across the workspaces (e.g. keypair signature array mismatches, missing imports, and type warnings in oracle-event-listener.ts) to ensure a completely clean build.

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tariff-shield-web Error Error Jul 27, 2026 10:26pm

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

The `vercel.json` schema validation failed with the following message: should NOT have additional property `rootDirectory`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@fhayvy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add BRIN Index on contract_events.created_at for Time-Range Queries

1 participant