Preserve activity descriptors on empty refresh

This commit is contained in:
Sipke Schoorstra 2026-05-31 13:32:56 +02:00
parent 66af304364
commit 209f93bfb5
No known key found for this signature in database
GPG key ID: 5C10502B28A4268F
2 changed files with 2 additions and 30 deletions

View file

@ -192,13 +192,11 @@ public class ActivityRegistry(IActivityDescriber activityDescriber, IEnumerable<
// Group descriptors by normalized tenant ID
// Normalize null to "*" so both map to the same agnostic group, avoiding redundant processing
var descriptorsByTenant = descriptors.GroupBy(d => NormalizeTenantIdForGrouping(d.TenantId));
var refreshedRegistries = new HashSet<TenantRegistryData>();
foreach (var group in descriptorsByTenant)
{
var tenantId = group.Key;
var registry = GetOrCreateRegistry(tenantId);
refreshedRegistries.Add(registry);
// Remove old descriptors for this provider from this tenant's registry
if (registry.ProvidedActivityDescriptors.TryGetValue(providerType, out var oldDescriptors))
@ -219,20 +217,6 @@ public class ActivityRegistry(IActivityDescriber activityDescriber, IEnumerable<
// Update the provider's descriptor list in this registry
registry.ProvidedActivityDescriptors[providerType] = providerDescriptors;
}
foreach (var registry in GetRegistriesWithProvider(providerType))
{
if (refreshedRegistries.Contains(registry))
continue;
if (!registry.ProvidedActivityDescriptors.TryRemove(providerType, out var oldDescriptors))
continue;
foreach (var oldDescriptor in oldDescriptors.ToList())
{
RemoveDescriptor(registry, oldDescriptor);
}
}
}
private void Add(ActivityDescriptor? descriptor, TenantRegistryData registry, ICollection<ActivityDescriptor> providerDescriptors)
@ -322,18 +306,6 @@ public class ActivityRegistry(IActivityDescriber activityDescriber, IEnumerable<
return registry.ProvidedActivityDescriptors.GetOrAdd(providerType, _ => new List<ActivityDescriptor>());
}
private IEnumerable<TenantRegistryData> GetRegistriesWithProvider(Type providerType)
{
if (_agnosticRegistry.ProvidedActivityDescriptors.ContainsKey(providerType))
yield return _agnosticRegistry;
foreach (var registry in _tenantRegistries.Values)
{
if (registry.ProvidedActivityDescriptors.ContainsKey(providerType))
yield return registry;
}
}
private static void UpdateLatestDescriptor(TenantRegistryData registry, ActivityDescriptor descriptor)
{
registry.LatestActivityDescriptors.AddOrUpdate(

View file

@ -405,7 +405,7 @@ public class ActivityRegistryTests
}
[Fact]
public async Task RefreshDescriptorsAsync_RemovesLatestDescriptor_WhenProviderDropsTenantGroup()
public async Task RefreshDescriptorsAsync_PreservesExistingDescriptors_WhenProviderReturnsNoTenantGroups()
{
// Arrange
var provider = new MutableProvider(
@ -422,7 +422,7 @@ public class ActivityRegistryTests
var result = _registry.Find(TestActivityType);
// Assert
Assert.Null(result);
AssertDescriptor(result, CurrentTenant, 2);
}