feat(connectors): disable cache config (#1349)
.NET Test / test (push) Has been cancelled
.NET Build and Publish / build-connectors (push) Has been cancelled
.NET Build and Publish / deploy-installers (push) Has been cancelled

* feat(all): adds disable cache functionality

* feat(connectors): prevents StoreSendResult if cache disabled

* fix(connectors): restores IsBypassed state

* Explicit flag instead implicit

* Delete unused flag

* Add packfile support

---------

Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com>
Co-authored-by: oguzhankoral <oguzhankoral@gmail.com>
Co-authored-by: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com>
This commit is contained in:
Björn Steinhagen
2026-04-08 12:27:22 +02:00
committed by GitHub
parent 0441cf7e3c
commit 3bb0860d14
5 changed files with 51 additions and 17 deletions
@@ -505,7 +505,16 @@ public class SendComponentWorker : WorkerInstance<SendAsyncComponent>
using var scope = PriorityLoader.CreateScopeForActiveDocument();
var sendOperation = scope.ServiceProvider.GetRequiredService<SendOperation<SpeckleCollectionWrapperGoo>>();
(SendOperationResult result, string versionId, string? ingestionId) = await sendOperation
.Send([rootCollectionWrapper], sendInfo, fileName, fileBytes, Parent.VersionMessage, progress, CancellationToken)
.Send(
[rootCollectionWrapper],
sendInfo,
fileName,
fileBytes,
Parent.VersionMessage,
progress,
true,
CancellationToken
)
.ConfigureAwait(false);
if (ingestionId != null)
@@ -283,7 +283,7 @@ public class SendComponent : SpeckleTaskCapableComponent<SendComponentInput, Sen
using var client = clientFactory.Create(account);
var sendInfo = await input.Resource.GetSendInfo(client, cancellationToken).ConfigureAwait(false);
var (result, versionId, ingestionId) = await sendOperation
.Send([collectionToSend], sendInfo, fileName, fileBytes, VersionMessage, progress, cancellationToken)
.Send([collectionToSend], sendInfo, fileName, fileBytes, VersionMessage, progress, true, cancellationToken)
.ConfigureAwait(false);
if (ingestionId != null)
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Extensions;
using Speckle.Connectors.Common.Operations;
@@ -7,6 +8,7 @@ using Speckle.Connectors.DUI.Exceptions;
using Speckle.Connectors.DUI.Logging;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Connectors.DUI.Settings;
using Speckle.InterfaceGenerator;
using Speckle.Sdk;
using Speckle.Sdk.Api;
@@ -38,8 +40,7 @@ public sealed class SendOperationManager(
Func<SenderModelCard, IReadOnlyList<T>> gatherObjects,
string? fileName,
long? fileSizeBytes
)
{
) =>
await Process(
commands,
modelCardId,
@@ -48,7 +49,6 @@ public sealed class SendOperationManager(
fileName,
fileSizeBytes
);
}
public async Task Process<T>(
ISendBindingUICommands commands,
@@ -57,8 +57,7 @@ public sealed class SendOperationManager(
Func<SenderModelCard, Task<IReadOnlyList<T>>> gatherObjects,
string? fileName,
long? fileSizeBytes
)
{
) =>
await Process(
commands,
modelCardId,
@@ -67,7 +66,6 @@ public sealed class SendOperationManager(
fileName,
fileSizeBytes
);
}
public async Task Process<T>(
ISendBindingUICommands commands,
@@ -79,6 +77,7 @@ public sealed class SendOperationManager(
)
{
using var activity = activityFactory.Start();
var sendConversionCache = serviceScope.ServiceProvider.GetRequiredService<ISendConversionCache>();
try
{
if (store.GetModelById(modelCardId) is not SenderModelCard modelCard)
@@ -86,6 +85,7 @@ public sealed class SendOperationManager(
// Handle as GLOBAL ERROR at BrowserBridge
throw new InvalidOperationException("No publish model card was found.");
}
using SendInfo sendInfo = GetSendInfo(modelCard);
using var userScope = UserActivityScope.AddUserScope(sendInfo.Account);
@@ -93,6 +93,14 @@ public sealed class SendOperationManager(
initializeScope(serviceScope.ServiceProvider, modelCard);
// if user has disabled cache, wipe the in-memory cache before gathering and building objects
var configStore = serviceScope.ServiceProvider.GetRequiredService<IConfigStore>();
var isCacheDisabled = configStore.GetConnectorConfig().DisableCache;
if (isCacheDisabled)
{
sendConversionCache.ClearCache(); // clear whatever is currently in there to ensure 0% cache hits
}
var progress = operationProgressManager.CreateOperationProgressEventHandler(
commands.Bridge,
modelCardId,
@@ -116,6 +124,7 @@ public sealed class SendOperationManager(
fileSizeBytes,
null,
progress,
saveToCache: !isCacheDisabled,
cancellationItem.Token
);
@@ -165,6 +165,8 @@ public sealed class ConnectorConfig
{
public bool DarkTheme { get; init; } = true;
public bool DisableCache { get; init; }
/// <remarks>
/// Only used by Revit Connector !!
/// We're exposing some settings to disable event listening inorder to debug app crash issues caused by Revit event handlers
@@ -45,6 +45,7 @@ public sealed class SendOperation<T>(
long? fileSizeBytes,
string? versionMessage,
IProgress<CardProgress> uiProgress,
bool saveToCache,
CancellationToken cancellationToken
)
{
@@ -62,6 +63,7 @@ public sealed class SendOperation<T>(
fileSizeBytes,
versionMessage,
uiProgress,
saveToCache,
cancellationToken
);
}
@@ -72,12 +74,13 @@ public sealed class SendOperation<T>(
fileSizeBytes,
versionMessage,
uiProgress,
saveToCache,
cancellationToken
);
}
else
{
return await SendViaVersionCreate(objects, sendInfo, versionMessage, uiProgress, cancellationToken);
return await SendViaVersionCreate(objects, sendInfo, versionMessage, uiProgress, saveToCache, cancellationToken);
}
}
@@ -90,6 +93,7 @@ public sealed class SendOperation<T>(
string? versionMessage,
#pragma warning restore IDE0060
IProgress<CardProgress> uiProgress,
bool saveToCache,
CancellationToken cancellationToken
)
{
@@ -136,8 +140,10 @@ public sealed class SendOperation<T>(
);
buildResult.RootObject["version"] = 3;
WriteReferencesToCache(buildResult.ConversionResults, sendInfo.ProjectId);
if (saveToCache)
{
WriteReferencesToCache(buildResult.ConversionResults, sendInfo.ProjectId);
}
SendOperationResult result =
new(buildResult.RootObject.id!, new Dictionary<Id, ObjectReference>(), buildResult.ConversionResults);
@@ -175,6 +181,7 @@ public sealed class SendOperation<T>(
long? fileSizeBytes,
string? versionMessage,
IProgress<CardProgress> uiProgress,
bool saveToCache,
CancellationToken cancellationToken
)
{
@@ -199,7 +206,7 @@ public sealed class SendOperation<T>(
AggregateProgress<CardProgress> progress = new(ingestionProgress, uiProgress);
try
{
SendOperationResult result = await ConvertAndSend(objects, sendInfo, progress, cancellationToken);
SendOperationResult result = await ConvertAndSend(objects, sendInfo, progress, saveToCache, cancellationToken);
string createdVersionId = await sendInfo.Client.Ingestion.Complete(
new(ingestion.id, sendInfo.ProjectId, result.RootObjId, versionMessage),
@@ -234,10 +241,11 @@ public sealed class SendOperation<T>(
SendInfo sendInfo,
string? versionMessage,
IProgress<CardProgress> progress,
bool saveToCache,
CancellationToken cancellationToken
)
{
SendOperationResult result = await ConvertAndSend(objects, sendInfo, progress, cancellationToken);
SendOperationResult result = await ConvertAndSend(objects, sendInfo, progress, saveToCache, cancellationToken);
Version version = await sendInfo.Client.Version.Create(
new(
@@ -256,10 +264,11 @@ public sealed class SendOperation<T>(
IReadOnlyList<T> objects,
SendInfo sendInfo,
IProgress<CardProgress> onOperationProgressed,
CancellationToken ct = default
bool saveToCache,
CancellationToken cancellationToken
)
{
var buildResult = await Build(objects, sendInfo.ProjectId, onOperationProgressed, ct);
var buildResult = await Build(objects, sendInfo.ProjectId, onOperationProgressed, cancellationToken);
// base object handler is separated, so we can do some testing on non-production databases
// exact interface may want to be tweaked when we implement this
var results = await threadContext.RunOnWorkerAsync(async () =>
@@ -269,7 +278,8 @@ public sealed class SendOperation<T>(
sendInfo.ProjectId,
sendInfo.Account,
onOperationProgressed,
ct
saveToCache,
cancellationToken
);
return results;
@@ -296,6 +306,7 @@ public sealed class SendOperation<T>(
string projectId,
Account account,
IProgress<CardProgress> onOperationProgressed,
bool saveToCache,
CancellationToken cancellationToken
)
{
@@ -314,7 +325,10 @@ public sealed class SendOperation<T>(
cancellationToken
);
sendConversionCache.StoreSendResult(projectId, sendResult.ConvertedReferences);
if (saveToCache)
{
sendConversionCache.StoreSendResult(projectId, sendResult.ConvertedReferences);
}
cancellationToken.ThrowIfCancellationRequested();