nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: textileio/go-threads
Pull request #480 (2021-01-15 22:11:10)

Fixes error when chaining skip and limit
Fixes a simple error when skip and limit are chained, leading to what is essentially an offset. This also adds a test for this case. In addition to fixing an error, this PR makes the query more strict about what it "counts". It no longer counts instances that are set to nil by the read filter.


Patch:
diff --git a/db/query.go b/db/query.go
index edb03c5..66e1ea9 100644
--- a/db/query.go
+++ b/db/query.go
@@ -326,11 +326,14 @@ func (t *Txn) Find(q *Query) ([][]byte, error) {
 		if err != nil {
 			return nil, err
 		}
-		count++
-		if res.Value != nil && count > q.Skip {
-			values = append(values, res)
+		if res.Value != nil {
+			// Only count valid values that aren't filtered by the read filter
+			count++
+			if count > q.Skip {
+				values = append(values, res)
+			}
 		}
-		if count == q.Limit {
+		if len(values) == q.Limit {
 			break
 		}
 	}


Test patch:
diff --git a/db/query_more_test.go b/db/query_more_test.go
index 77e2d91..5c54e05 100644
--- a/db/query_more_test.go
+++ b/db/query_more_test.go
@@ -92,6 +92,8 @@ var (
 
 		{name: "LimitTotalReadsOutside", query: Where("Meta.TotalReads").Gt(float64(100)).LimitTo(2), resIdx: []int{3, 4}},
 		{name: "LimitTotalReadsInside", query: Where("Meta.TotalReads").Lt(float64(100)).LimitTo(2), resIdx: []int{0, 1}},
+
+		{name: "LimitWithSkip", query: Where("Meta.TotalReads").Gt(float64(0)).SkipNum(1).LimitTo(3), resIdx: []int{1, 2, 3}},
 	}
 )