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

Allow SDK to report requested downloaded objects and minor adjustments #203

Merged
merged 2 commits into from
Jan 13, 2025
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
4 changes: 2 additions & 2 deletions src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public abstract class ChannelLoader<T>
private const int MAX_PARALLELISM_HTTP = 4;
private static readonly TimeSpan HTTP_BATCH_TIMEOUT = TimeSpan.FromSeconds(2);
private static readonly int MAX_READ_CACHE_PARALLELISM = Environment.ProcessorCount;
private const int MAX_SAVE_CACHE_BATCH = 200;
private const int MAX_SAVE_CACHE_PARALLELISM = 1;
private const int MAX_SAVE_CACHE_BATCH = 500;
private const int MAX_SAVE_CACHE_PARALLELISM = 4;

protected async Task GetAndCache(IEnumerable<string> allChildrenIds, CancellationToken cancellationToken = default) =>
await allChildrenIds
Expand Down
5 changes: 5 additions & 0 deletions src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed class ObjectLoader(
private int? _allChildrenCount;
private long _checkCache;
private long _cached;
private long _downloaded;
private long _totalToDownload;
private DeserializeProcessOptions _options = new(false);

[AutoInterfaceIgnore]
Expand Down Expand Up @@ -72,6 +74,7 @@ CancellationToken cancellationToken
progress?.Report(new(ProgressEvent.CacheCheck, _checkCache, _allChildrenCount));
if (!_options.SkipCache && !sqLiteJsonCacheManager.HasObject(id))
{
Interlocked.Increment(ref _totalToDownload);
return id;
}

Expand All @@ -86,6 +89,8 @@ public override async Task<List<BaseItem>> Download(List<string?> ids)
var (id, json) in serverObjectManager.DownloadObjects(ids.Select(x => x.NotNull()).ToList(), progress, default)
)
{
Interlocked.Increment(ref _downloaded);
progress?.Report(new(ProgressEvent.DownloadObjects, _downloaded, _totalToDownload));
toCache.Add(new(new(id), new(json), true, null));
}

Expand Down
13 changes: 4 additions & 9 deletions src/Speckle.Sdk/Serialisation/V2/Send/SerializeProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public async Task<SerializeProcessResults> Serialize(Base root, CancellationToke
);
}

await Traverse(root, true, cancellationToken).ConfigureAwait(false);
await Traverse(root, cancellationToken).ConfigureAwait(false);
await Done().ConfigureAwait(true);
await channelTask.ConfigureAwait(false);
await findTotalObjectsTask.ConfigureAwait(false);
return new(root.id.NotNull(), _objectReferences.Freeze());
Expand All @@ -93,7 +94,7 @@ private void TraverseTotal(Base obj)
}
}

private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj, bool isEnd, CancellationToken cancellationToken)
private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj, CancellationToken cancellationToken)
{
var tasks = new List<Task<Dictionary<Id, NodeInfo>>>();
foreach (var child in baseChildFinder.GetChildren(obj))
Expand All @@ -102,7 +103,7 @@ private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj, bool isEnd, Canc
var tmp = child;
var t = Task
.Factory.StartNew(
() => Traverse(tmp, false, cancellationToken),
() => Traverse(tmp, cancellationToken),
cancellationToken,
TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness,
_belowNormal
Expand Down Expand Up @@ -145,12 +146,6 @@ private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj, bool isEnd, Canc
}
}
_childClosurePool.Return(childClosures);

if (isEnd)
{
await Done().ConfigureAwait(true);
}

return currentClosures;
}

Expand Down
1 change: 1 addition & 0 deletions src/Speckle.Sdk/Transports/ProgressArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum ProgressEvent

CacheCheck,
DownloadBytes,
DownloadObjects,
DeserializeObject,

SerializeObject, // old
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public async Task IsFrontEnd2True()
result.frontend2.Should().BeTrue();
}

[Fact]
public async Task IsFrontEnd2False()
{
ServerInfo? result = await Fixtures
.ServiceProvider.GetRequiredService<IAccountManager>()
.GetServerInfo(new("https://speckle.xyz/"));

result.Should().NotBeNull();
result.frontend2.Should().BeFalse();
}

/// <remarks>
/// We get ServerInfo from "http://localhost:3000/graphql",
/// Then we mutate the `frontend2` property of ServerInfo by trying to fetch header from "http://localhost:3000/",
Expand Down
Loading