Skip to content

Commit

Permalink
leave desc behavior as is
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Aug 5, 2024
1 parent 2f946a0 commit f2ddcfa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
10 changes: 0 additions & 10 deletions services/horizon/internal/actions/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const (
DisableCursorValidation Opt = iota
// DefaultTOID sets a default cursor value in GetPageQuery based on the ledger state
DefaultTOID Opt = iota

defaultLedgerCursorBuffer = 100
)

// HeaderWriter is an interface for setting HTTP response headers
Expand Down Expand Up @@ -228,14 +226,6 @@ func GetPageQuery(ledgerState *ledger.State, r *http.Request, opts ...Opt) (db2.
pageQuery.Cursor = toid.AfterLedger(
ordered.Max(0, ledgerState.CurrentStatus().HistoryElder-1),
).String()
} else if pageQuery.Order == db2.OrderDescending {
pageQuery.Cursor = toid.AfterLedger(
// add an extra amount to the latest ledger in case the
// ledger state is out of date
ledgerState.CurrentStatus().HistoryLatest + defaultLedgerCursorBuffer,
).String()
} else {
return db2.PageQuery{}, problem.BadRequest
}
}

Expand Down
6 changes: 3 additions & 3 deletions services/horizon/internal/actions/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func TestGetPageQueryCursorDefaultTOID(t *testing.T) {

pq, err = GetPageQuery(ledgerState, descReq, DefaultTOID)
assert.NoError(t, err)
assert.Equal(t, toid.AfterLedger(7000+defaultLedgerCursorBuffer).String(), pq.Cursor)
assert.Equal(t, "", pq.Cursor)
assert.Equal(t, uint64(2), pq.Limit)
assert.Equal(t, "desc", pq.Order)

Expand All @@ -324,7 +324,7 @@ func TestGetPageQueryCursorDefaultTOID(t *testing.T) {
pq, err = GetPageQuery(ledgerState, descReq)
assert.NoError(t, err)
assert.Empty(t, pq.Cursor)
assert.Equal(t, uint64(2), pq.Limit)
assert.Equal(t, "", pq.Cursor)
assert.Equal(t, "desc", pq.Order)

ledgerState.SetHorizonStatus(ledger.HorizonStatus{
Expand All @@ -342,7 +342,7 @@ func TestGetPageQueryCursorDefaultTOID(t *testing.T) {

pq, err = GetPageQuery(ledgerState, descReq, DefaultTOID)
assert.NoError(t, err)
assert.Equal(t, toid.AfterLedger(7000+defaultLedgerCursorBuffer).String(), pq.Cursor)
assert.Equal(t, "", pq.Cursor)
assert.Equal(t, uint64(2), pq.Limit)
assert.Equal(t, "desc", pq.Order)

Expand Down

0 comments on commit f2ddcfa

Please sign in to comment.