From 752e0ac0d2e5e395f71cc845bc8ff5f6be304109 Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:45:02 -0800 Subject: [PATCH] Don't parse if no args and result (#77) --- .../Binary/Builders/CodecBuilder.cs | 10 +++++++--- .../Binary/Protocol/IProtocolProvider.cs | 2 +- .../Binary/Protocol/V1.0/V1ProtocolProvider.cs | 10 ++++++++-- src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs | 12 ++++++++---- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/EdgeDB.Net.Driver/Binary/Builders/CodecBuilder.cs b/src/EdgeDB.Net.Driver/Binary/Builders/CodecBuilder.cs index 5707006e..9b9d46c1 100644 --- a/src/EdgeDB.Net.Driver/Binary/Builders/CodecBuilder.cs +++ b/src/EdgeDB.Net.Driver/Binary/Builders/CodecBuilder.cs @@ -36,9 +36,13 @@ internal sealed class CodecBuilder { public static readonly ConcurrentDictionary CodecCaches = new(); - public static readonly Guid NullCodec = Guid.Empty; + public static readonly Guid NullCodecId = Guid.Empty; public static readonly Guid InvalidCodec = Guid.Parse("ffffffffffffffffffffffffffffffff"); + public static readonly NullCodec NullCodec = new NullCodec(); + + public static readonly CodecInfo NullCodecInfo = new(NullCodecId, NullCodec); + private static readonly ConcurrentDictionary _codecKeyMap = new(); private static readonly List _scalarCodecs; @@ -46,7 +50,7 @@ internal sealed class CodecBuilder private static readonly Dictionary _scalarCodecTypeMap = new() { - {NullCodec, typeof(NullCodec)}, + {NullCodecId, typeof(NullCodec)}, {new Guid("00000000-0000-0000-0000-000000000100"), typeof(UUIDCodec)}, {new Guid("00000000-0000-0000-0000-000000000101"), typeof(TextCodec)}, {new Guid("00000000-0000-0000-0000-000000000102"), typeof(BytesCodec)}, @@ -141,7 +145,7 @@ public static ICodec BuildCodec(EdgeDBBinaryClient client, in Guid id, byte[] bu public static ICodec BuildCodec(EdgeDBBinaryClient client, in Guid id, ref PacketReader reader) { - if (id == NullCodec) + if (id == NullCodecId) return GetOrCreateCodec(client.ProtocolProvider); var providerCache = GetProviderCache(client.ProtocolProvider); diff --git a/src/EdgeDB.Net.Driver/Binary/Protocol/IProtocolProvider.cs b/src/EdgeDB.Net.Driver/Binary/Protocol/IProtocolProvider.cs index c115a6bf..b3caba8f 100644 --- a/src/EdgeDB.Net.Driver/Binary/Protocol/IProtocolProvider.cs +++ b/src/EdgeDB.Net.Driver/Binary/Protocol/IProtocolProvider.cs @@ -45,7 +45,7 @@ public static void UpdateProviderFor(EdgeDBBinaryClient client, IProtocolProvide PacketReadFactory? GetPacketFactory(ServerMessageType type); - Task ParseQueryAsync(QueryParameters query, CancellationToken token); + ValueTask ParseQueryAsync(QueryParameters query, CancellationToken token); Task ExecuteQueryAsync(QueryParameters query, ParseResult result, CancellationToken token); diff --git a/src/EdgeDB.Net.Driver/Binary/Protocol/V1.0/V1ProtocolProvider.cs b/src/EdgeDB.Net.Driver/Binary/Protocol/V1.0/V1ProtocolProvider.cs index f2aff44b..cc3f7bbe 100644 --- a/src/EdgeDB.Net.Driver/Binary/Protocol/V1.0/V1ProtocolProvider.cs +++ b/src/EdgeDB.Net.Driver/Binary/Protocol/V1.0/V1ProtocolProvider.cs @@ -183,16 +183,22 @@ public virtual async Task ExecuteQueryAsync(QueryParameters query return new ExecuteResult(receivedData.ToArray(), parseResult.OutCodecInfo); } - public virtual async Task ParseQueryAsync(QueryParameters queryParameters, CancellationToken token) + public virtual async ValueTask ParseQueryAsync(QueryParameters queryParameters, CancellationToken token) { ErrorResponse? error = null; var parseAttempts = 0; var successfullyParsed = false; var gotStateDescriptor = false; + var stateBuf = _client.SerializeState(); + + if (queryParameters.Arguments is null && queryParameters.Format == IOFormat.None) + { + return new ParseResult(CodecBuilder.NullCodecInfo, CodecBuilder.NullCodecInfo, in stateBuf); + } + var cacheKey = queryParameters.GetCacheKey(); - var stateBuf = _client.SerializeState(); if (!CodecBuilder.TryGetCodecs(this, cacheKey, out var inCodecInfo, out var outCodecInfo)) { diff --git a/src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs b/src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs index 4aed6f44..d0bab5fc 100644 --- a/src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs +++ b/src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs @@ -147,18 +147,22 @@ async Task ITransactibleClient.StartTransactionAsync(Isolation isolation, bool r var deferMode = $"{(!deferrable ? "not " : "")}deferrable"; - await ExecuteInternalAsync($"start transaction isolation {isolationMode}, {readMode}, {deferMode}", - capabilities: Capabilities.Transaction, token: token).ConfigureAwait(false); + await ExecuteInternalAsync( + $"start transaction isolation {isolationMode}, {readMode}, {deferMode}", + capabilities: Capabilities.Transaction, + format: IOFormat.None, + token: token + ).ConfigureAwait(false); } /// async Task ITransactibleClient.CommitAsync(CancellationToken token) - => await ExecuteInternalAsync("commit", capabilities: Capabilities.Transaction, token: token) + => await ExecuteInternalAsync("commit", capabilities: Capabilities.Transaction, token: token, format: IOFormat.None) .ConfigureAwait(false); /// async Task ITransactibleClient.RollbackAsync(CancellationToken token) - => await ExecuteInternalAsync("rollback", capabilities: Capabilities.Transaction, token: token) + => await ExecuteInternalAsync("rollback", capabilities: Capabilities.Transaction, token: token, format: IOFormat.None) .ConfigureAwait(false); ///