Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't parse if no args and result #77

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading