Skip to content

Commit f7f74cd

Browse files
authored
fix: offset from paging (#185)
### TL;DR Fixed pagination offset calculation in token balances query. ### What changed? Modified the offset calculation in the `GetTokenBalances` method to use `qf.Page * qf.Limit` instead of `(qf.Page - 1) * qf.Limit`. This changes how pagination works when retrieving token balances from the ClickHouse database. ### How to test? 1. Query token balances with pagination parameters (page > 0, limit > 0) 2. Verify that the correct records are returned for each page 3. Check that there is no overlap or gap between consecutive pages ### Why make this change? The previous calculation assumed page numbers started at 1, but params in insight-service use pages starting with `0`. This fix ensures that the correct offset is calculated when paginating through token balances, preventing duplicate records or skipped entries when navigating through pages.
2 parents b8832b3 + 4be8822 commit f7f74cd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/storage/clickhouse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ func (c *ClickHouseConnector) GetTokenBalances(qf BalancesQueryFilter, fields ..
16041604

16051605
// Add limit clause
16061606
if qf.Page > 0 && qf.Limit > 0 {
1607-
offset := (qf.Page - 1) * qf.Limit
1607+
offset := qf.Page * qf.Limit
16081608
query += fmt.Sprintf(" LIMIT %d OFFSET %d", qf.Limit, offset)
16091609
} else if qf.Limit > 0 {
16101610
query += fmt.Sprintf(" LIMIT %d", qf.Limit)

0 commit comments

Comments
 (0)