Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Oct 25, 2024
1 parent acf420a commit fa9fe32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/Speckle.Sdk.Dependencies/Serialization/ChannelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ public abstract class ChannelLoader
{
private const int HTTP_ID_CHUNK_SIZE = 500;
private const int MAX_PARALLELISM_HTTP = 4;

protected async Task GetAndCache(IEnumerable<string> allChildrenIds, CancellationToken cancellationToken = default) =>
await allChildrenIds
.ToChannel(cancellationToken: cancellationToken)
.Pipe(Environment.ProcessorCount, CheckCache, cancellationToken: cancellationToken)
.Filter(x => x is not null)
.Batch(HTTP_ID_CHUNK_SIZE)
.WithTimeout(TimeSpan.FromSeconds(2))
.PipeAsync(MAX_PARALLELISM_HTTP, async x => await DownloadAndCache(x).ConfigureAwait(false), -1, false, cancellationToken)
.PipeAsync(
MAX_PARALLELISM_HTTP,
async x => await DownloadAndCache(x).ConfigureAwait(false),
-1,
false,
cancellationToken
)
.Join()
.ReadAllConcurrently(Environment.ProcessorCount, SaveToCache, cancellationToken)
.ConfigureAwait(false);


public abstract string? CheckCache(string id);

public abstract Task<List<(string, string)>> DownloadAndCache(List<string?> ids);

public abstract void SaveToCache((string, string) x);

}
4 changes: 1 addition & 3 deletions src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public sealed class ObjectLoader(
IProgress<ProgressArgs>? progress
) : ChannelLoader, IObjectLoader
{

private int? _allChildrenCount;
private long _checkCache;
private long _cached;
Expand Down Expand Up @@ -48,8 +47,7 @@ CancellationToken cancellationToken
.Where(x => !x.StartsWith("blob", StringComparison.Ordinal))
.ToList();
_allChildrenCount = allChildrenIds.Count;
await GetAndCache(allChildrenIds, cancellationToken)
.ConfigureAwait(false);
await GetAndCache(allChildrenIds, cancellationToken).ConfigureAwait(false);

//save the root last to shortcut later
sqLiteCacheManager.SaveObjectSync(rootId, rootJson);
Expand Down
2 changes: 1 addition & 1 deletion src/Speckle.Sdk/Serialisation/V2/SQLiteCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public bool HasObject(string objectId)
bool rowFound = reader.Read();
return rowFound;
}

public void SaveObjectSync(string hash, string serializedObject)
{
using var c = new SqliteConnection(_connectionString);
Expand Down

0 comments on commit fa9fe32

Please sign in to comment.