Repository navigation
chore: add indexes for invoice listing per namespace - #3512
Conversation
This improves the performance of list invoices pages.
📝 WalkthroughWalkthroughAdds four composite indexes on billing_invoices (namespace with period_start, created_at, updated_at, issued_at) across Ent schema, generated migrate schema, and SQL migrations. Includes corresponding up/down SQL to create/drop these indexes. No changes to exported APIs or runtime logic. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
openmeter/ent/schema/billing.go (1)
997-1000: LGTM! Indexes support efficient invoice listing per namespace.The four composite indexes on
(namespace, timestamp_field)are well-designed for supporting sorted invoice listings within a namespace, which aligns with the PR objective.Optional optimization: If your queries commonly filter out NULL values (e.g.,
WHERE issued_at IS NOT NULL), consider using partial indexes to reduce index size and improve performance:index.Fields("namespace", "period_start"), + .Annotations( + entsql.IndexWhere("period_start IS NOT NULL"), + ), index.Fields("namespace", "created_at"), index.Fields("namespace", "updated_at"), index.Fields("namespace", "issued_at"), + .Annotations( + entsql.IndexWhere("issued_at IS NOT NULL"), + ),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
go.sumis excluded by!**/*.sumtools/migrate/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (4)
openmeter/ent/db/migrate/schema.go(1 hunks)openmeter/ent/schema/billing.go(1 hunks)tools/migrate/migrations/20251014132051_invoice-order-by-indexes.down.sql(1 hunks)tools/migrate/migrations/20251014132051_invoice-order-by-indexes.up.sql(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
openmeter/ent/db/migrate/schema.go (1)
openmeter/ent/db/billinginvoice/billinginvoice.go (1)
Columns(206-263)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Artifacts / Container image
- GitHub Check: Artifacts / Benthos Collector Container image
- GitHub Check: Migration Checks
- GitHub Check: Lint
- GitHub Check: Test
- GitHub Check: Build
- GitHub Check: Code Generators
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
tools/migrate/migrations/20251014132051_invoice-order-by-indexes.down.sql (1)
1-8: LGTM! Down migration correctly reverses the index creation.The migration properly drops all four indexes created in the up migration, ensuring clean rollback capability.
openmeter/ent/db/migrate/schema.go (1)
679-698: LGTM! Generated schema matches the source definitions.The four new indexes on
billing_invoicesare correctly generated from the Ent schema definitions. The structure matches the indexes defined inopenmeter/ent/schema/billing.go.tools/migrate/migrations/20251014132051_invoice-order-by-indexes.up.sql (1)
1-8: LGTM! Up migration correctly creates all required indexes.The migration creates four composite indexes on
billing_invoicesthat will efficiently support namespace-scoped queries ordered by timestamp fields. The index definitions match the schema specification.
Overview
This improves the performance of list invoices pages.
Summary by CodeRabbit