From 350f7adb2a087811a70f1c05bf71014022aefeb4 Mon Sep 17 00:00:00 2001 From: Baha Aiman Date: Thu, 7 Sep 2023 14:10:37 -0700 Subject: [PATCH] fix(firestore): Correcting EndBefore with LimitToLast behaviour (#8370) * fix(firestore): Correcting endBefore with limitToLast behaviour * fix(firestore): Adding test --- firestore/integration_test.go | 2 ++ firestore/query.go | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/firestore/integration_test.go b/firestore/integration_test.go index a4b180e74853..7f881a855f1c 100644 --- a/firestore/integration_test.go +++ b/firestore/integration_test.go @@ -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) diff --git a/firestore/query.go b/firestore/query.go index 26f89832cf27..ed5e83582a4c 100644 --- a/firestore/query.go +++ b/firestore/query.go @@ -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