Skip to content

Commit

Permalink
Don't parse if no args and result (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs authored Mar 1, 2024
1 parent 2179dea commit 752e0ac
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/EdgeDB.Net.Driver/Binary/Builders/CodecBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ internal sealed class CodecBuilder
{
public static readonly ConcurrentDictionary<IProtocolProvider, CodecCache> 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<ulong, (Guid InCodec, Guid OutCodec)> _codecKeyMap = new();

private static readonly List<ICodec> _scalarCodecs;
private static readonly ConcurrentDictionary<Type, IScalarCodec> _scalarCodecMap;

private static readonly Dictionary<Guid, Type> _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)},
Expand Down Expand Up @@ -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<NullCodec>(client.ProtocolProvider);

var providerCache = GetProviderCache(client.ProtocolProvider);
Expand Down
2 changes: 1 addition & 1 deletion src/EdgeDB.Net.Driver/Binary/Protocol/IProtocolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void UpdateProviderFor(EdgeDBBinaryClient client, IProtocolProvide

PacketReadFactory? GetPacketFactory(ServerMessageType type);

Task<ParseResult> ParseQueryAsync(QueryParameters query, CancellationToken token);
ValueTask<ParseResult> ParseQueryAsync(QueryParameters query, CancellationToken token);

Task<ExecuteResult> ExecuteQueryAsync(QueryParameters query, ParseResult result, CancellationToken token);

Expand Down
10 changes: 8 additions & 2 deletions src/EdgeDB.Net.Driver/Binary/Protocol/V1.0/V1ProtocolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,22 @@ public virtual async Task<ExecuteResult> ExecuteQueryAsync(QueryParameters query
return new ExecuteResult(receivedData.ToArray(), parseResult.OutCodecInfo);
}

public virtual async Task<ParseResult> ParseQueryAsync(QueryParameters queryParameters, CancellationToken token)
public virtual async ValueTask<ParseResult> 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))
{
Expand Down
12 changes: 8 additions & 4 deletions src/EdgeDB.Net.Driver/Clients/EdgeDBTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <inheritdoc />
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);

/// <inheritdoc />
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);

/// <inheritdoc />
Expand Down

0 comments on commit 752e0ac

Please sign in to comment.