< 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]
 21511public class CachingHttpWorkflowLookupService(
 21512    IHttpWorkflowLookupService decoratedService,
 21513    IHttpWorkflowsCacheManager cacheManager,
 21514    ITenantAccessor tenantAccessor) : IHttpWorkflowLookupService
 15{
 16    /// <inheritdoc />
 17    public async Task<HttpWorkflowLookupResult?> FindWorkflowAsync(string bookmarkHash, CancellationToken cancellationTo
 18    {
 21519        var tenant = tenantAccessor.Tenant;
 21520        var tenantId = tenant?.Id;
 21521        var tenantIdPrefix = !string.IsNullOrEmpty(tenantId) ? $"{tenantId}:" : string.Empty;
 21522        var key = $"{tenantIdPrefix}http-workflow:{bookmarkHash}";
 21523        var cache = cacheManager.Cache;
 21524        return await cache.GetOrCreateAsync(key, async entry =>
 21525        {
 20926            var cachingOptions = cache.CachingOptions.Value;
 20927            entry.SetSlidingExpiration(cachingOptions.CacheDuration);
 20928            entry.AddExpirationToken(cache.GetToken(cacheManager.GetTriggerChangeTokenKey(bookmarkHash)));
 21529
 20930            var result = await decoratedService.FindWorkflowAsync(bookmarkHash, cancellationToken);
 21531
 20932            if (result == null)
 233                return null;
 21534
 20735            if(result.WorkflowGraph == null)
 036                return result;
 21537
 20738            var workflowGraph = result.WorkflowGraph!;
 20739            var changeTokenKey = cacheManager.GetWorkflowChangeTokenKey(workflowGraph.Workflow.Identity.DefinitionId);
 20740            var changeToken = cache.GetToken(changeTokenKey);
 20741            entry.AddExpirationToken(changeToken);
 21542
 20743            return result;
 42444        });
 21545    }
 46}