-
Notifications
You must be signed in to change notification settings - Fork 117
feat: add some pagination options #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: refacto/pagination-system
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
0545e6a
to
ffcd47d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## refacto/pagination-system #980 +/- ##
=============================================================
- Coverage 82.92% 82.89% -0.04%
=============================================================
Files 145 145
Lines 8199 8219 +20
=============================================================
+ Hits 6799 6813 +14
- Misses 1075 1081 +6
Partials 325 325 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug
The UpdateAccountsMetadata
method now accepts a time.Time
parameter (at
) to set FirstUsage
. This introduces two issues with the SQL update logic for first_usage
:
- When
time.Time{}
(zero time, January 1, year 1) is passed forat
(e.g., in test calls or metadata-only updates), thecase when excluded.first_usage < accounts.first_usage then excluded.first_usage else accounts.first_usage end
condition incorrectly setsfirst_usage
to zero time, as zero time is always earlier than any valid timestamp. This can overwrite existing correctfirst_usage
values. - The same SQL logic fails to correctly set
first_usage
whenaccounts.first_usage
isNULL
andexcluded.first_usage
has a real timestamp. The comparisonreal_date < NULL
evaluates toNULL
(unknown), causing theCASE
statement to retain theNULL
value.
These issues lead tofirst_usage
being corrupted or not set properly, preventing accurate tracking of account first usage.
internal/storage/ledger/accounts.go#L24-L62
ledger/internal/storage/ledger/accounts.go
Lines 24 to 62 in ffcd47d
func (store *Store) UpdateAccountsMetadata(ctx context.Context, m map[string]metadata.Metadata, at time.Time) error { | |
_, err := tracing.TraceWithMetric( | |
ctx, | |
"UpdateAccountsMetadata", | |
store.tracer, | |
store.updateAccountsMetadataHistogram, | |
tracing.NoResult(func(ctx context.Context) error { | |
span := trace.SpanFromContext(ctx) | |
span.SetAttributes(attribute.StringSlice("accounts", Keys(m))) | |
type AccountWithLedger struct { | |
ledger.Account `bun:",extend"` | |
Ledger string `bun:"ledger,type:varchar"` | |
AddressArray []string `bun:"address_array,type:jsonb"` | |
} | |
accounts := make([]AccountWithLedger, 0) | |
for account, accountMetadata := range m { | |
accounts = append(accounts, AccountWithLedger{ | |
Ledger: store.ledger.Name, | |
Account: ledger.Account{ | |
Address: account, | |
Metadata: accountMetadata, | |
FirstUsage: at, | |
}, | |
AddressArray: strings.Split(account, ":"), | |
}) | |
} | |
ret, err := store.db.NewInsert(). | |
Model(&accounts). | |
ModelTableExpr(store.GetPrefixedRelationName("accounts")). | |
On("conflict (ledger, address) do update"). | |
Set("metadata = accounts.metadata || excluded.metadata"). | |
Set("updated_at = excluded.updated_at"). | |
Set("first_usage = case when excluded.first_usage < accounts.first_usage then excluded.first_usage else accounts.first_usage end"). | |
Where("not accounts.metadata @> excluded.metadata"). |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Fixes LX-62