Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into serialize-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Oct 25, 2024
2 parents 0edddd2 + f5a8d1a commit 808a1f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Open.ChannelExtensions;
using Open.ChannelExtensions;

namespace Speckle.Sdk.Dependencies.Serialization;

Expand Down
38 changes: 1 addition & 37 deletions src/Speckle.Sdk/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Net.WebSockets;
using System.Reflection;
using GraphQL;
Expand Down Expand Up @@ -175,46 +174,11 @@ internal void MaybeThrowFromGraphQLErrors<T>(GraphQLRequest request, GraphQLResp
}
}

private Dictionary<string, object?> ConvertExpandoToDict(ExpandoObject expando)
{
var variables = new Dictionary<string, object?>();
foreach (KeyValuePair<string, object?> 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<T>(GraphQLRequest request)
{
// i know this is double (de)serializing, but we need a recursive convert to
// dict<str, object> here
var expando = JsonConvert.DeserializeObject<ExpandoObject>(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<T>(GraphQLRequest request, Action<object, T> callback) =>
SubscribeTo(request, callback);

/// <inheritdoc cref="ISpeckleGraphQLClient.SubscribeTo{T}"/>
internal IDisposable SubscribeTo<T>(GraphQLRequest request, Action<object, T> callback)
private IDisposable SubscribeTo<T>(GraphQLRequest request, Action<object, T> callback)
{
//using (LogContext.Push(CreateEnrichers<T>(request)))
{
Expand Down
17 changes: 12 additions & 5 deletions src/Speckle.Sdk/Serialisation/V2/Receive/DeserializeProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public sealed class DeserializeProcess(IProgress<ProgressArgs>? progress, IObjec
private DeserializeOptions _options = new(false);

public ConcurrentDictionary<string, Base> BaseCache { get; } = new();
private readonly ConcurrentDictionary<string, Task> _activeTasks = new();

public async Task<Base> Deserialize(
string rootId,
Expand Down Expand Up @@ -42,13 +43,17 @@ private async Task Traverse(string id, CancellationToken cancellationToken)
var tasks = new List<Task>();
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
Expand All @@ -60,6 +65,7 @@ private async Task Traverse(string id, CancellationToken cancellationToken)
)
.Unwrap();
tasks.Add(t);
_activeTasks.TryAdd(childId, t);
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 808a1f5

Please sign in to comment.