Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/modules/Elsa.Workflows.Core/Services/ActivityRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,33 @@ public IEnumerable<ActivityDescriptor> ListByProvider(Type providerType)
}

/// <inheritdoc />
public ActivityDescriptor? Find(string type) => _activityDescriptors.Values.Where(x => (x.TenantId == tenantAccessor.TenantId || x.TenantId == null) && x.TypeName == type).MaxBy(x => x.Version);
public ActivityDescriptor? Find(string type)
{
var tenantId = tenantAccessor.TenantId;
ActivityDescriptor? tenantSpecific = null;
ActivityDescriptor? tenantAgnostic = null;

// Single-pass iteration to find both tenant-specific and tenant-agnostic descriptors
foreach (var descriptor in _activityDescriptors.Values)
{
if (descriptor.TypeName != type)
continue;

if (descriptor.TenantId == tenantId)
{
if (tenantSpecific == null || descriptor.Version > tenantSpecific.Version)
tenantSpecific = descriptor;
}
else if (descriptor.TenantId == null)
{
if (tenantAgnostic == null || descriptor.Version > tenantAgnostic.Version)
tenantAgnostic = descriptor;
}

Copilot AI Jan 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 'if' statements can be combined.

Suggested change
if (descriptor.TenantId == tenantId)
{
if (tenantSpecific == null || descriptor.Version > tenantSpecific.Version)
tenantSpecific = descriptor;
}
else if (descriptor.TenantId == null)
{
if (tenantAgnostic == null || descriptor.Version > tenantAgnostic.Version)
tenantAgnostic = descriptor;
}
if (descriptor.TenantId == tenantId && (tenantSpecific == null || descriptor.Version > tenantSpecific.Version))
tenantSpecific = descriptor;
else if (descriptor.TenantId == null && (tenantAgnostic == null || descriptor.Version > tenantAgnostic.Version))
tenantAgnostic = descriptor;

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 203e2ef. The nested if statements have been combined into single-line conditionals for improved readability.

}
Comment thread
sfmskywalker marked this conversation as resolved.

// Prefer tenant-specific over tenant-agnostic
return tenantSpecific ?? tenantAgnostic;
}
Comment thread
sfmskywalker marked this conversation as resolved.

/// <inheritdoc />
public ActivityDescriptor? Find(string type, int version) => _activityDescriptors.GetValueOrDefault((tenantAccessor.TenantId, type, version)) ?? _activityDescriptors.GetValueOrDefault((null, type, version));
Expand Down
Loading