< Summary

Information
Class: Elsa.Persistence.EFCore.Modules.Runtime.EFCoreWorkflowExecutionLogStore
Assembly: Elsa.Persistence.EFCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/WorkflowExecutionLogStore.cs
Line coverage
92%
Covered lines: 35
Uncovered lines: 3
Coverable lines: 38
Total lines: 106
Line coverage: 92.1%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
AddAsync()100%210%
AddManyAsync()100%11100%
SaveAsync()100%11100%
SaveManyAsync()100%11100%
FindAsync()100%11100%
FindAsync()100%11100%
FindManyAsync()100%11100%
FindManyAsync()100%11100%
DeleteManyAsync()100%11100%
OnSaveAsync(...)100%22100%
OnLoadAsync()50%2275%
LoadPayload(...)50%22100%
ShouldSerializePayload(...)75%4483.33%
Filter(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore/Modules/Runtime/WorkflowExecutionLogStore.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Common.Models;
 3using Elsa.Extensions;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Runtime;
 6using Elsa.Workflows.Runtime.Entities;
 7using Elsa.Workflows.Runtime.Extensions;
 8using Elsa.Workflows.Runtime.Filters;
 9using Elsa.Workflows.Runtime.OrderDefinitions;
 10using Open.Linq.AsyncExtensions;
 11
 12namespace Elsa.Persistence.EFCore.Modules.Runtime;
 13
 14/// <summary>
 15/// An EF Core implementation of <see cref="IWorkflowExecutionLogStore"/>.
 16/// </summary>
 42717public class EFCoreWorkflowExecutionLogStore(EntityStore<RuntimeElsaDbContext, WorkflowExecutionLogRecord> store, ISafeS
 18{
 19    /// <inheritdoc />
 020    public async Task AddAsync(WorkflowExecutionLogRecord record, CancellationToken cancellationToken = default) => awai
 21
 22    /// <inheritdoc />
 23    public async Task AddManyAsync(IEnumerable<WorkflowExecutionLogRecord> records, CancellationToken cancellationToken 
 24    {
 38425        await store.AddManyAsync(records, OnSaveAsync, cancellationToken);
 38426    }
 27
 28    /// <inheritdoc />
 29    public async Task SaveAsync(WorkflowExecutionLogRecord record, CancellationToken cancellationToken = default)
 30    {
 1531        await store.SaveAsync(record, OnSaveAsync, cancellationToken);
 1532    }
 33
 34    /// <inheritdoc />
 35    public async Task SaveManyAsync(IEnumerable<WorkflowExecutionLogRecord> records, CancellationToken cancellationToken
 36    {
 137        await store.SaveManyAsync(records, OnSaveAsync, cancellationToken);
 138    }
 39
 40    /// <inheritdoc />
 41    public async Task<WorkflowExecutionLogRecord?> FindAsync(WorkflowExecutionLogRecordFilter filter, CancellationToken 
 42    {
 1043        return await store.QueryAsync(queryable => Filter(queryable, filter).OrderByTimestampThenSequence(), OnLoadAsync
 544    }
 45
 46    /// <inheritdoc />
 47    public async Task<WorkflowExecutionLogRecord?> FindAsync<TOrderBy>(WorkflowExecutionLogRecordFilter filter, Workflow
 48    {
 249        return await store.QueryAsync(queryable => Filter(queryable, filter).OrderBy(order), OnLoadAsync, cancellationTo
 150    }
 51
 52    /// <inheritdoc />
 53    public async Task<Page<WorkflowExecutionLogRecord>> FindManyAsync(WorkflowExecutionLogRecordFilter filter, PageArgs 
 54    {
 4055        var count = await store.QueryAsync(queryable => Filter(queryable, filter), cancellationToken).LongCount();
 4056        var results = await store.QueryAsync(queryable => Filter(queryable, filter).OrderByTimestampThenSequence().Pagin
 2057        return new(results, count);
 2058    }
 59
 60    /// <inheritdoc />
 61    public async Task<Page<WorkflowExecutionLogRecord>> FindManyAsync<TOrderBy>(WorkflowExecutionLogRecordFilter filter,
 62    {
 663        var count = await store.QueryAsync(queryable => Filter(queryable, filter), cancellationToken).LongCount();
 664        var results = await store.QueryAsync(queryable => Filter(queryable, filter).OrderBy(order).Paginate(pageArgs), O
 365        return new(results, count);
 366    }
 67
 68    /// <inheritdoc />
 69    public async Task<long> DeleteManyAsync(WorkflowExecutionLogRecordFilter filter, CancellationToken cancellationToken
 70    {
 3471        return await store.DeleteWhereAsync(queryable => Filter(queryable, filter), cancellationToken);
 1772    }
 73
 74    private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord entity, CancellationToken c
 75    {
 529176        entity = entity.SanitizeLogMessage();
 529177        dbContext.Entry(entity).Property("SerializedPayload").CurrentValue = ShouldSerializePayload(entity) ? safeSerial
 529178        return ValueTask.CompletedTask;
 79    }
 80
 81    private async ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord? entity, Cancellation
 82    {
 7383        if (entity is null)
 084            return;
 85
 7386        entity.Payload = await LoadPayload(dbContext, entity);
 7387    }
 88
 89    private ValueTask<object?> LoadPayload(RuntimeElsaDbContext dbContext, WorkflowExecutionLogRecord entity)
 90    {
 7391        var json = dbContext.Entry(entity).Property<string>("SerializedPayload").CurrentValue;
 7392        return new(!string.IsNullOrEmpty(json) ? JsonSerializer.Deserialize<object>(json) : null);
 93    }
 94
 95    private bool ShouldSerializePayload(WorkflowExecutionLogRecord source)
 96    {
 529197        return source.Payload switch
 529198        {
 528599            null => false,
 0100            IDictionary<string, object> dictionary => dictionary.Count > 0,
 6101            _ => true
 5291102        };
 103    }
 104
 69105    private static IQueryable<WorkflowExecutionLogRecord> Filter(IQueryable<WorkflowExecutionLogRecord> queryable, Workf
 106}