Skip to content

Commit

Permalink
bjorn/cnx-1119-remove-caching-from-progress (#534)
Browse files Browse the repository at this point in the history
* Add PeriodicThreadedEvent to EA and use it

* All timers gone

* add tests

* bug: build issues

* bug: form not being disposed properly

* feat: remove caching

---------

Co-authored-by: Adam Hathcock <[email protected]>
  • Loading branch information
bjoernsteinhagen and adamhathcock authored Jan 29, 2025
1 parent 9219cdf commit 4d7225f
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Conversion;
using Speckle.Connectors.Common.Operations;
using Speckle.Connectors.CSiShared.HostApp;
using Speckle.Connectors.CSiShared.HostApp.Helpers;
using Speckle.Converters.Common;
using Speckle.Converters.CSiShared;
using Speckle.Converters.CSiShared.Extensions;
using Speckle.Sdk;
using Speckle.Sdk.Logging;
using Speckle.Sdk.Models;
Expand All @@ -30,7 +30,6 @@ namespace Speckle.Connectors.CSiShared.Builders;
public class CsiRootObjectBuilder : IRootObjectBuilder<ICsiWrapper>
{
private readonly IRootToSpeckleConverter _rootToSpeckleConverter;
private readonly ISendConversionCache _sendConversionCache;
private readonly IConverterSettingsStore<CsiConversionSettings> _converterSettings;
private readonly CsiSendCollectionManager _sendCollectionManager;
private readonly MaterialUnpacker _materialUnpacker;
Expand All @@ -41,7 +40,6 @@ public class CsiRootObjectBuilder : IRootObjectBuilder<ICsiWrapper>

public CsiRootObjectBuilder(
IRootToSpeckleConverter rootToSpeckleConverter,
ISendConversionCache sendConversionCache,
IConverterSettingsStore<CsiConversionSettings> converterSettings,
CsiSendCollectionManager sendCollectionManager,
MaterialUnpacker materialUnpacker,
Expand All @@ -51,7 +49,6 @@ public CsiRootObjectBuilder(
ICsiApplicationService csiApplicationService
)
{
_sendConversionCache = sendConversionCache;
_converterSettings = converterSettings;
_sendCollectionManager = sendCollectionManager;
_materialUnpacker = materialUnpacker;
Expand Down Expand Up @@ -94,7 +91,7 @@ CancellationToken cancellationToken
cancellationToken.ThrowIfCancellationRequested();
using var _2 = _activityFactory.Start("Convert");

var result = ConvertCsiObject(csiObject, rootObjectCollection, sendInfo.ProjectId);
var result = ConvertCsiObject(csiObject, rootObjectCollection);
results.Add(result);

count++;
Expand Down Expand Up @@ -123,22 +120,20 @@ CancellationToken cancellationToken
/// <summary>
/// Converts a single Csi wrapper "object" to a data object with appropriate collection management.
/// </summary>
private SendConversionResult ConvertCsiObject(ICsiWrapper csiObject, Collection typeCollection, string projectId)
private SendConversionResult ConvertCsiObject(ICsiWrapper csiObject, Collection typeCollection)
{
string applicationId = $"{csiObject.ObjectType}{csiObject.Name}"; // TODO: NO! Use GUID
string sourceType = csiObject.ObjectName;
string applicationId = csiObject switch
{
CsiFrameWrapper frameWrapper => frameWrapper.GetSpeckleApplicationId(_csiApplicationService.SapModel),
CsiJointWrapper jointWrapper => jointWrapper.GetSpeckleApplicationId(_csiApplicationService.SapModel),
CsiShellWrapper shellWrapper => shellWrapper.GetSpeckleApplicationId(_csiApplicationService.SapModel),
_ => throw new ArgumentException($"Unsupported wrapper type: {csiObject.GetType()}", nameof(csiObject))
};

try
{
Base converted;
if (_sendConversionCache.TryGetValue(projectId, applicationId, out ObjectReference? value))
{
converted = value;
}
else
{
converted = _rootToSpeckleConverter.Convert(csiObject);
}
Base converted = _rootToSpeckleConverter.Convert(csiObject);

var collection = _sendCollectionManager.AddObjectCollectionToRoot(converted, typeCollection);
collection.elements.Add(converted);
Expand Down

0 comments on commit 4d7225f

Please sign in to comment.