Skip to content

Commit

Permalink
add ability for objectloader to skip server too. (#228)
Browse files Browse the repository at this point in the history
* add ability for objectloader to skip server too.  add test so both cache and server can't be skipped

* move testing project to correct dir

* remove extra file
  • Loading branch information
adamhathcock authored Feb 13, 2025
1 parent f0bafee commit 2352306
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Speckle.Sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Serialization.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Dependencies", "src\Speckle.Sdk.Dependencies\Speckle.Sdk.Dependencies.csproj", "{27584AB4-8ACD-4850-8CC2-7E5BC739FB78}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Testing", "Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj", "{7B617C0D-2354-415C-993C-5071D4113E27}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speckle.Sdk.Testing", "tests\Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj", "{7B617C0D-2354-415C-993C-5071D4113E27}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "performance", "performance", "{FFB07238-87E8-463A-AA39-3B38AAAA94C1}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public record DeserializeProcessOptions(
bool SkipCache = false,
bool ThrowOnMissingReferences = true,
bool SkipInvalidConverts = false,
int? MaxParallelism = null
int? MaxParallelism = null,
bool SkipServer = false
);

public partial interface IDeserializeProcess : IDisposable;
Expand Down
45 changes: 25 additions & 20 deletions src/Speckle.Sdk/Serialisation/V2/Receive/ObjectLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,33 @@ CancellationToken cancellationToken
return (new(rootJson), allChildren);
}
}
rootJson = await serverObjectManager
.DownloadSingleObject(rootId, progress, cancellationToken)
.NotNull()
.ConfigureAwait(false);
IReadOnlyCollection<Id> allChildrenIds = ClosureParser
.GetClosures(rootJson, cancellationToken)
.OrderByDescending(x => x.Item2)
.Select(x => new Id(x.Item1))
.Where(x => !x.Value.StartsWith("blob", StringComparison.Ordinal))
.Freeze();
_allChildrenCount = allChildrenIds.Count;
await GetAndCache(allChildrenIds.Select(x => x.Value), cancellationToken, _options.MaxParallelism)
.ConfigureAwait(false);

CheckForExceptions();
cancellationToken.ThrowIfCancellationRequested();
//save the root last to shortcut later
if (!options.SkipCache)
if (!options.SkipServer)
{
sqLiteJsonCacheManager.SaveObject(rootId, rootJson);
rootJson = await serverObjectManager
.DownloadSingleObject(rootId, progress, cancellationToken)
.NotNull()
.ConfigureAwait(false);
IReadOnlyCollection<Id> allChildrenIds = ClosureParser
.GetClosures(rootJson, cancellationToken)
.OrderByDescending(x => x.Item2)
.Select(x => new Id(x.Item1))
.Where(x => !x.Value.StartsWith("blob", StringComparison.Ordinal))
.Freeze();
_allChildrenCount = allChildrenIds.Count;
await GetAndCache(allChildrenIds.Select(x => x.Value), cancellationToken, _options.MaxParallelism)
.ConfigureAwait(false);

CheckForExceptions();
cancellationToken.ThrowIfCancellationRequested();
//save the root last to shortcut later
if (!options.SkipCache)
{
sqLiteJsonCacheManager.SaveObject(rootId, rootJson);
}

return (new(rootJson), allChildrenIds);
}
return (new(rootJson), allChildrenIds);
throw new SpeckleException("Cannot skip server and cache. Please choose one.");
}

[AutoInterfaceIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Speckle.Objects\Speckle.Objects.csproj" />
<ProjectReference Include="..\..\Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj" />
<ProjectReference Include="..\Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Type": "Speckle.Sdk.SpeckleException",
"Message": "Cannot skip server and cache. Please choose one.",
"Source": "Speckle.Sdk"
}
24 changes: 24 additions & 0 deletions tests/Speckle.Sdk.Serialization.Tests/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ public async Task Test_Exceptions_Cache()
await Verify(ex);
}

[Fact]
public async Task Test_Exceptions_Receive_Server_Skip_Both()
{
var o = new ObjectLoader(
new DummySqLiteReceiveManager(new Dictionary<string, string>()),
new ExceptionServerObjectManager(),
null
);
using var process = new DeserializeProcess(
null,
o,
new BaseDeserializer(new ObjectDeserializerFactory()),
new NullLoggerFactory(),
default,
new(SkipCache: true, MaxParallelism: 1, SkipServer: true)
);

var ex = await Assert.ThrowsAsync<SpeckleException>(async () =>
{
var root = await process.Deserialize(Guid.NewGuid().ToString());
});
await Verify(ex);
}

[Theory]
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
public async Task Test_Exceptions_Receive_Server(string fileName, string rootId, int oldCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj" />
<ProjectReference Include="..\Speckle.Sdk.Testing\Speckle.Sdk.Testing.csproj" />
<ProjectReference Include="..\..\src\Speckle.Objects\Speckle.Objects.csproj" />
</ItemGroup>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Speckle.Sdk\Speckle.Sdk.csproj" />
<ProjectReference Include="..\..\src\Speckle.Sdk\Speckle.Sdk.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2352306

Please sign in to comment.