From e9db5d0f6748b8c1e263f85906440525845f262e Mon Sep 17 00:00:00 2001 From: slorello89 Date: Mon, 15 Jul 2024 08:06:26 -0400 Subject: [PATCH] setting internal cursor to 0 when no cursor is called for --- .../Aggregation/AggregationEnumerator.cs | 10 ++++++- .../RediSearchTests/AggregationSetTests.cs | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Redis.OM/Aggregation/AggregationEnumerator.cs b/src/Redis.OM/Aggregation/AggregationEnumerator.cs index 4a0f2070..ce347821 100644 --- a/src/Redis.OM/Aggregation/AggregationEnumerator.cs +++ b/src/Redis.OM/Aggregation/AggregationEnumerator.cs @@ -39,6 +39,10 @@ internal AggregationEnumerator(Expression exp, IRedisConnection connection, int _aggregation = ExpressionTranslator.BuildAggregationFromExpression(exp, typeof(T)); _connection = connection; _useCursor = useCursor; + if (!_useCursor) + { + _cursor = 0; + } } /// @@ -164,7 +168,11 @@ public async ValueTask MoveNextAsync() /// public void Reset() { - _cursor = -1; + if (_useCursor) + { + _cursor = -1; + } + _index = 0; _chunk = Array.Empty>(); } diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs index 288b1fa7..4f1ef418 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs @@ -31,6 +31,24 @@ RedisReply MockedResult } } + RedisReply MockedResultWithoutCursor + { + get + { + var replyList = new List(); + replyList.Add(new RedisReply(1)); + for(var i = 0; i < 1000; i++) + { + replyList.Add(new RedisReply(new RedisReply[] + { + $"FakeResult", + "blah" + })); + } + return replyList.ToArray(); + } + } + RedisReply MockedResultCursorEnd { get @@ -629,5 +647,17 @@ public void TestMultiPredicateFilter() _ = collection.Filter(query).ToList(); _substitute.Received().Execute("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'", "WITHCURSOR", "COUNT", "10000"); } + + [Fact] + public async Task TestNoCursorDelete() + { + var collection = new RedisAggregationSet(_substitute); + _substitute.ExecuteAsync("FT.AGGREGATE", Arg.Any()).Returns(MockedResultWithoutCursor); + + Expression, bool>> query = a => a.RecordShell!.TagField == "foo" && a.RecordShell.Address.State == "FL"; + _ = await collection.Filter(query).ToListAsync(); + await _substitute.Received().ExecuteAsync("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'"); + await _substitute.DidNotReceive().ExecuteAsync("FT.CURSOR", Arg.Any()); + } } }