From 73660cb906cc50e2cfc549382b921b69042545e7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 Aug 2025 01:30:41 +0000 Subject: [PATCH 1/3] Initial plan From 91d881a7c1b42f54b70c78fd8b8f3a89d126dd33 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 Aug 2025 01:47:06 +0000 Subject: [PATCH 2/3] Implement ExecutionStrategy for Cosmos query execution Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Storage/Internal/CosmosClientWrapper.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs index 439fff3f856..020a61a3d93 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs @@ -900,6 +900,14 @@ private static JsonTextReader CreateJsonReader(TextReader reader) return jsonReader; } + private static ResponseMessage ExecuteReadNext((FeedIterator Query, CosmosClientWrapper Wrapper) state) + => state.Query.ReadNextAsync().GetAwaiter().GetResult(); + + private static Task ExecuteReadNextAsync( + (FeedIterator Query, CosmosClientWrapper Wrapper) state, + CancellationToken cancellationToken) + => state.Query.ReadNextAsync(cancellationToken); + private sealed class DocumentEnumerable( CosmosClientWrapper cosmosClient, string containerId, @@ -960,7 +968,10 @@ public bool MoveNext() return false; } - _responseMessage = _query.ReadNextAsync().GetAwaiter().GetResult(); + _responseMessage = _cosmosClientWrapper._executionStrategy.Execute( + (_query, _cosmosClientWrapper), + static (_, state) => ExecuteReadNext(state), + null); _cosmosClientWrapper._commandLogger.ExecutedReadNext( _responseMessage.Diagnostics.GetClientElapsedTime(), @@ -1061,7 +1072,11 @@ public async ValueTask MoveNextAsync() return false; } - _responseMessage = await _query.ReadNextAsync(cancellationToken).ConfigureAwait(false); + _responseMessage = await _cosmosClientWrapper._executionStrategy.ExecuteAsync( + (_query, _cosmosClientWrapper), + static (_, state, cancellationToken) => ExecuteReadNextAsync(state, cancellationToken), + null, + cancellationToken).ConfigureAwait(false); _cosmosClientWrapper._commandLogger.ExecutedReadNext( _responseMessage.Diagnostics.GetClientElapsedTime(), From bdbfbbd4baafd567e66469693e20abb1deb5397a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 Aug 2025 02:18:59 +0000 Subject: [PATCH 3/3] Inline ExecuteReadNext helper methods as requested Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Storage/Internal/CosmosClientWrapper.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs index 020a61a3d93..495e48135c4 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs @@ -900,14 +900,6 @@ private static JsonTextReader CreateJsonReader(TextReader reader) return jsonReader; } - private static ResponseMessage ExecuteReadNext((FeedIterator Query, CosmosClientWrapper Wrapper) state) - => state.Query.ReadNextAsync().GetAwaiter().GetResult(); - - private static Task ExecuteReadNextAsync( - (FeedIterator Query, CosmosClientWrapper Wrapper) state, - CancellationToken cancellationToken) - => state.Query.ReadNextAsync(cancellationToken); - private sealed class DocumentEnumerable( CosmosClientWrapper cosmosClient, string containerId, @@ -970,7 +962,7 @@ public bool MoveNext() _responseMessage = _cosmosClientWrapper._executionStrategy.Execute( (_query, _cosmosClientWrapper), - static (_, state) => ExecuteReadNext(state), + static (_, state) => state._query.ReadNextAsync().GetAwaiter().GetResult(), null); _cosmosClientWrapper._commandLogger.ExecutedReadNext( @@ -1074,7 +1066,7 @@ public async ValueTask MoveNextAsync() _responseMessage = await _cosmosClientWrapper._executionStrategy.ExecuteAsync( (_query, _cosmosClientWrapper), - static (_, state, cancellationToken) => ExecuteReadNextAsync(state, cancellationToken), + static (_, state, cancellationToken) => state._query.ReadNextAsync(cancellationToken), null, cancellationToken).ConfigureAwait(false);