Skip to content

Commit

Permalink
fix(firestore): Correcting EndBefore with LimitToLast behaviour (#8370)
Browse files Browse the repository at this point in the history
* fix(firestore): Correcting endBefore with limitToLast behaviour

* fix(firestore): Adding test
  • Loading branch information
bhshkh authored Sep 7, 2023
1 parent 5ef93de commit 350f7ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions firestore/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,8 @@ func TestIntegration_QueryDocuments(t *testing.T) {
{q.EndAt(1), wants[:2], true},
{q.EndBefore(1), wants[:1], true},
{q.LimitToLast(2), wants[1:], true},
{q.EndBefore(2).LimitToLast(2), wants[:2], true},
{q.StartAt(1).EndBefore(2).LimitToLast(3), wants[1:2], true},
} {
if test.orderBy {
test.q = test.q.OrderBy("q", Asc)
Expand Down
8 changes: 6 additions & 2 deletions firestore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,12 @@ func (it *DocumentIterator) GetAll() ([]*DocumentSnapshot, error) {
// Swap cursors.
q.startVals, q.endVals = q.endVals, q.startVals
q.startDoc, q.endDoc = q.endDoc, q.startDoc
q.startBefore, q.endBefore = q.endBefore, q.startBefore

if q.endBefore {
q.endBefore = false
q.startBefore = false
} else {
q.startBefore, q.endBefore = q.endBefore, q.startBefore
}
q.limitToLast = false
}
var docs []*DocumentSnapshot
Expand Down

0 comments on commit 350f7ad

Please sign in to comment.