From 51cd3fa851e7092b82ba6e11bc54a2aa22a77a3d Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 29 May 2024 10:35:42 +0200 Subject: [PATCH] Update and optimize WorkflowDefinitionStore logic (#5462) The update involves optimizing the WorkflowDefinitionStore logic. The minor change is that it removed an unneeded space in the CountDistinctAsync method. More importantly, an upgrade issue with 'IsSystem' from older versions of Elsa to 3.2 has been rectified by adding checks and conditions to suit legacy versions. In the future, once all systems are updated, this check can be removed. --- .../Modules/Management/WorkflowDefinitionStore.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/modules/Elsa.EntityFrameworkCore/Modules/Management/WorkflowDefinitionStore.cs b/src/modules/Elsa.EntityFrameworkCore/Modules/Management/WorkflowDefinitionStore.cs index fcd7efa94..2c6886075 100644 --- a/src/modules/Elsa.EntityFrameworkCore/Modules/Management/WorkflowDefinitionStore.cs +++ b/src/modules/Elsa.EntityFrameworkCore/Modules/Management/WorkflowDefinitionStore.cs @@ -140,7 +140,7 @@ public class EFCoreWorkflowDefinitionStore : IWorkflowDefinitionStore /// public async Task CountDistinctAsync(CancellationToken cancellationToken = default) { - return await _store.CountAsync(x => true, x => x.DefinitionId, cancellationToken); + return await _store.CountAsync(x => true, x => x.DefinitionId, cancellationToken); } /// @@ -193,7 +193,14 @@ public class EFCoreWorkflowDefinitionStore : IWorkflowDefinitionStore if (filter.Names != null) queryable = queryable.Where(x => filter.Names.Contains(x.Name!)); if (filter.UsableAsActivity != null) queryable = queryable.Where(x => EF.Property(x, "UsableAsActivity") == filter.UsableAsActivity); if (!string.IsNullOrWhiteSpace(filter.SearchTerm)) queryable = queryable.Where(x => x.Name!.Contains(filter.SearchTerm) || x.Description!.Contains(filter.SearchTerm) || x.Id.Contains(filter.SearchTerm) || x.DefinitionId.Contains(filter.SearchTerm)); - if (filter.IsSystem != null) queryable = queryable.Where(x => x.IsSystem == filter.IsSystem); + + // TEMP: IsSystem may be null when upgrading from older versions of Elsa to 3.2. See issue #5366. + // In a future version, we should remove this check and simply do queryable.Where(x => x.IsSystem == filter.IsSystem). + if (filter.IsSystem != null) + queryable = filter.IsSystem == true + ? queryable.Where(x => x.IsSystem == true) + : queryable.Where(x => x.IsSystem == false || x.IsSystem == null); + if (filter.IsReadonly != null) queryable = queryable.Where(x => x.IsReadonly == filter.IsReadonly); return queryable; } @@ -204,7 +211,7 @@ public class EFCoreWorkflowDefinitionStore : IWorkflowDefinitionStore if (pageArgs?.Limit != null) queryable = queryable.Take(pageArgs.Limit.Value); return queryable; } - + private class WorkflowDefinitionState { [JsonConstructor]