You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(notification): use the annotations GIN index for balance hash lookups - #5498
The balance worker reads the latest matching Event in a namespace and usage period using either its V1 or V2 hash. Previously, the adapter extracted the annotation as text, so PostgreSQL had to filter candidate Events after scanning the namespace index.
Use JSONB containment on the existing annotations column for each hash and combine the predicates with OR. This lets PostgreSQL use the existing GIN index for both the pagination count and the newest-Event lookup.
Notes for reviewer
The adapter tests cover V1, V2, mixed history, an unknown hash, and exclusion by annotation key, namespace and usage period. The mixed-history case checks that two Events count as matches while only the latest is returned.
On a local PostgreSQL 15 fixture with 100,000 Events, the old plans read 25,000 candidates through the namespace index and discarded 24,980. With the new predicate, both plans combined two scans on notificationevent_annotations using BitmapOr and fetched 20 matches.
Query
Before
After
Count
7.657 ms
0.405 ms
Newest Event
4.650 ms
0.312 ms
Timings are from a single local fixture run.
The PostgreSQL-backed Notification adapter suite passed with -race -tags=dynamic, and package lint reported zero issues.
Summary by CodeRabbit
Bug Fixes
Event listings now correctly match requested deduplication hashes, including when multiple hashes are provided.
Filtering continues to respect namespace and time range, with accurate result counts and newest-first ordering.
Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.
Summary
Changes balance hash lookups from extracted-text comparisons to JSONB containment, allowing PostgreSQL to use the existing GIN index.
Balance event lookups can use the annotations index for either hash.
No actionable comments were generated in the recent review.
Walkthrough
ListEvents now matches each requested deduplication hash against a complete JSON object in event annotations. Tests cover hash combinations, namespace and time filters, result counts, and ordering.
Changes: Event deduplication hash filtering
Layer / File(s)
Summary
Update and verify hash filtering openmeter/notification/adapter/event.go, openmeter/notification/adapter/event_test.go
ListEvents combines whole-object JSON containment matches for requested hashes with OR. Tests check legacy and current hashes, unknown hashes, namespace and time filters, total counts, and newest-first results with a one-item page.
This change switches balance hash lookups to a query form that can use the existing annotations index. No behavioral risk was found. The release-note label check still needs a label applied before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: balance hash lookups in the notification event adapter now use the annotations GIN index. The raw summary confirms ListEvents switched from entutils.JSONBIn on the ded…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: balance hash lookups in the notification event adapter now use the annotations GIN index. The raw summary confirms ListEvents switched from entutils.JSONBIn on the dedup-hash key to per-hash JSON containment matches combined with OR, and the objectives state the same goal. The title is specific and matches the changeset, and it follows the conventional commit style used in the repository.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Reviewing files that changed from the base of the PR and between a209bda and 69621fd.
Files selected for processing: 2
openmeter/notification/adapter/event.go
openmeter/notification/adapter/event_test.go
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
The balance worker reads the latest matching Event in a namespace and usage period using either its V1 or V2 hash. Previously, the adapter extracted the annotation as text, so PostgreSQL had to filter candidate Events after scanning the namespace index.
Use JSONB containment on the existing annotations column for each hash and combine the predicates with OR. This lets PostgreSQL use the existing GIN index for both the pagination count and the newest-Event lookup.
Notes for reviewer
The adapter tests cover V1, V2, mixed history, an unknown hash, and exclusion by annotation key, namespace and usage period. The mixed-history case checks that two Events count as matches while only the latest is returned.
On a local PostgreSQL 15 fixture with 100,000 Events, the old plans read 25,000 candidates through the namespace index and discarded 24,980. With the new predicate, both plans combined two scans on
notificationevent_annotationsusingBitmapOrand fetched 20 matches.Timings are from a single local fixture run.
The PostgreSQL-backed Notification adapter suite passed with
-race -tags=dynamic, and package lint reported zero issues.Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Changes balance hash lookups from extracted-text comparisons to JSONB containment, allowing PostgreSQL to use the existing GIN index.
Reviews (1) · Last reviewed commit: "perf(notification): use the annotations ..." · Reviewed by Greptile