< Summary

Information
Class: Elsa.Http.Services.CachingHttpWorkflowLookupService
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/CachingHttpWorkflowLookupService.cs
Line coverage
96%
Covered lines: 30
Uncovered lines: 1
Coverable lines: 31
Total lines: 46
Line coverage: 96.7%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
FindWorkflowAsync()50%44100%
<FindWorkflowAsync()75%4492.85%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Services/CachingHttpWorkflowLookupService.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using JetBrains.Annotations;
 3using Microsoft.Extensions.Caching.Memory;
 4
 5namespace Elsa.Http.Services;
 6
 7/// <summary>
 8/// Represents a caching implementation of the IHttpWorkflowLookupService that retrieves workflows using HTTP workflow l
 9/// </summary>
 10[UsedImplicitly]
 27011public class CachingHttpWorkflowLookupService(
 27012    IHttpWorkflowLookupService decoratedService,
 27013    IHttpWorkflowsCacheManager cacheManager,
 27014    ITenantAccessor tenantAccessor) : IHttpWorkflowLookupService
 15{
 16    /// <inheritdoc />
 17    public async Task<HttpWorkflowLookupResult?> FindWorkflowAsync(string bookmarkHash, CancellationToken cancellationTo
 18    {
 27019        var tenant = tenantAccessor.Tenant;
 27020        var tenantId = tenant?.Id;
 27021        var tenantIdPrefix = !string.IsNullOrEmpty(tenantId) ? $"{tenantId}:" : string.Empty;
 27022        var key = $"{tenantIdPrefix}http-workflow:{bookmarkHash}";
 27023        var cache = cacheManager.Cache;
 27024        return await cache.FindOrCreateAsync(key, async entry =>
 27025        {
 11526            var cachingOptions = cache.CachingOptions.Value;
 11527            entry.SetSlidingExpiration(cachingOptions.CacheDuration);
 11528            entry.AddExpirationToken(cache.GetToken(cacheManager.GetTriggerChangeTokenKey(bookmarkHash)));
 27029
 11530            var result = await decoratedService.FindWorkflowAsync(bookmarkHash, cancellationToken);
 27031
 11532            if (result == null)
 633                return null;
 27034
 10935            if(result.WorkflowGraph == null)
 036                return result;
 27037
 10938            var workflowGraph = result.WorkflowGraph!;
 10939            var changeTokenKey = cacheManager.GetWorkflowChangeTokenKey(workflowGraph.Workflow.Identity.DefinitionId);
 10940            var changeToken = cache.GetToken(changeTokenKey);
 10941            entry.AddExpirationToken(changeToken);
 27042
 10943            return result;
 38544        });
 27045    }
 46}