diff --git a/src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs b/src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs index 7afaad2a..590ee359 100644 --- a/src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs +++ b/src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs @@ -1,4 +1,4 @@ -using Open.ChannelExtensions; +using Open.ChannelExtensions; namespace Speckle.Sdk.Dependencies.Serialization; diff --git a/src/Speckle.Sdk/Api/GraphQL/Client.cs b/src/Speckle.Sdk/Api/GraphQL/Client.cs index 37fa525b..2dadff62 100644 --- a/src/Speckle.Sdk/Api/GraphQL/Client.cs +++ b/src/Speckle.Sdk/Api/GraphQL/Client.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Dynamic; using System.Net.WebSockets; using System.Reflection; using GraphQL; @@ -175,46 +174,11 @@ internal void MaybeThrowFromGraphQLErrors(GraphQLRequest request, GraphQLResp } } - private Dictionary ConvertExpandoToDict(ExpandoObject expando) - { - var variables = new Dictionary(); - foreach (KeyValuePair kvp in expando) - { - object? value; - if (kvp.Value is ExpandoObject ex) - { - value = ConvertExpandoToDict(ex); - } - else - { - value = kvp.Value; - } - - variables[kvp.Key] = value; - } - return variables; - } - - /* private ILogEventEnricher[] CreateEnrichers(GraphQLRequest request) - { - // i know this is double (de)serializing, but we need a recursive convert to - // dict here - var expando = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(request.Variables)); - var variables = request.Variables != null && expando != null ? ConvertExpandoToDict(expando) : null; - return new ILogEventEnricher[] - { - new PropertyEnricher("serverUrl", ServerUrl), - new PropertyEnricher("graphqlQuery", request.Query), - new PropertyEnricher("graphqlVariables", variables), - new PropertyEnricher("resultType", typeof(T).Name) - }; - }*/ - IDisposable ISpeckleGraphQLClient.SubscribeTo(GraphQLRequest request, Action callback) => SubscribeTo(request, callback); /// - internal IDisposable SubscribeTo(GraphQLRequest request, Action callback) + private IDisposable SubscribeTo(GraphQLRequest request, Action callback) { //using (LogContext.Push(CreateEnrichers(request))) { diff --git a/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs b/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs index 21581903..322cc92e 100644 --- a/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs +++ b/src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs @@ -14,6 +14,7 @@ public sealed class DeserializeProcess(IProgress? progress, IObjec private DeserializeOptions _options = new(false); public ConcurrentDictionary BaseCache { get; } = new(); + private readonly ConcurrentDictionary _activeTasks = new(); public async Task Deserialize( string rootId, @@ -42,13 +43,17 @@ private async Task Traverse(string id, CancellationToken cancellationToken) var tasks = new List(); foreach (var childId in childIds) { - lock (BaseCache) + if (BaseCache.ContainsKey(childId)) { - if (BaseCache.ContainsKey(childId)) - { - continue; - } + continue; + } + if (_activeTasks.TryGetValue(childId, out var task)) + { + tasks.Add(task); + } + else + { // tmp is necessary because of the way closures close over loop variables var tmpId = childId; Task t = Task @@ -60,6 +65,7 @@ private async Task Traverse(string id, CancellationToken cancellationToken) ) .Unwrap(); tasks.Add(t); + _activeTasks.TryAdd(childId, t); } } @@ -104,6 +110,7 @@ public void DecodeOrEnqueueChildren(string id) BaseCache.TryAdd(id, @base); //remove from JSON cache because we've finally made the Base _closures.TryRemove(id, out _); + _activeTasks.TryRemove(id, out _); } private Base Deserialise(string id, string json)