Skip to content

Conversation

@turip
Copy link
Member

@turip turip commented Oct 14, 2025

Overview

This improves the performance of list invoices pages.

Summary by CodeRabbit

  • Refactor
    • Optimized invoice retrieval, delivering faster loading and smoother sorting/filtering by Created, Updated, Issued, and Period Start dates in billing views. Users should see improved responsiveness with large datasets, reduced timeouts, and quicker navigation across invoice pages and related endpoints. No functional changes to billing behavior; this update focuses on performance and scalability for everyday invoice browsing and reporting tasks.

This improves the performance of list invoices pages.
@turip turip requested a review from a team as a code owner October 14, 2025 13:21
@turip turip requested a review from hekike October 14, 2025 13:22
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Ent index definitions
openmeter/ent/schema/billing.go
Extends BillingInvoice indexes to include namespace combined with period_start, created_at, updated_at, issued_at; adjusts index construction and predicates.
Ent migrate schema
openmeter/ent/db/migrate/schema.go
Adds four non-unique indexes on billing_invoices for namespace with period_start/created_at/updated_at/issued_at.
SQL migrations
tools/migrate/migrations/20251014132051_invoice-order-by-indexes.up.sql, tools/migrate/migrations/20251014132051_invoice-order-by-indexes.down.sql
Up: creates four composite indexes on billing_invoices; Down: drops the same four indexes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change of the pull request by indicating that indexes are being added to support invoice listing scoped by namespace, which aligns precisely with the changes introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/add-indexes-for-invoice-listing

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.

❤️ Share

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

@turip turip added release-note/misc Miscellaneous changes area/billing labels Oct 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc1d1d4 and af1661f.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • tools/migrate/migrations/atlas.sum is 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_invoices are correctly generated from the Ent schema definitions. The structure matches the indexes defined in openmeter/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_invoices that will efficiently support namespace-scoped queries ordered by timestamp fields. The index definitions match the schema specification.

@turip turip enabled auto-merge (squash) October 14, 2025 13:44
@turip turip merged commit 955df78 into main Oct 14, 2025
30 of 32 checks passed
@turip turip deleted the chore/add-indexes-for-invoice-listing branch October 14, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants