| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Common.Services; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Workflows.Runtime.Entities; |
| | | 6 | | using Elsa.Workflows.Runtime.Filters; |
| | | 7 | | using Elsa.Workflows.Runtime.OrderDefinitions; |
| | | 8 | | using JetBrains.Annotations; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Workflows.Runtime.Stores; |
| | | 11 | | |
| | | 12 | | /// <inheritdoc /> |
| | | 13 | | [UsedImplicitly] |
| | 499 | 14 | | public class MemoryBookmarkQueueStore(MemoryStore<BookmarkQueueItem> store, ITenantAccessor? tenantAccessor = null) : IB |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public Task SaveAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 18 | | { |
| | 2 | 19 | | store.Save(record, x => x.Id); |
| | 1 | 20 | | return Task.CompletedTask; |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public Task AddAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 24 | | { |
| | 222 | 25 | | store.Add(record, x => x.Id); |
| | 111 | 26 | | return Task.CompletedTask; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public Task<BookmarkQueueItem?> FindAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 31 | | { |
| | 14 | 32 | | var entity = store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 7 | 33 | | return Task.FromResult(entity); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueItemOrder<TOrderBy> orderBy |
| | | 37 | | { |
| | 312 | 38 | | var entities = store.Query(query => query.WhereVisibleToTenant(CurrentTenantId).OrderBy(orderBy)).Paginate(pageA |
| | 156 | 39 | | return Task.FromResult(entities); |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | public Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueFilter filter, BookmarkQueu |
| | | 43 | | { |
| | 134 | 44 | | var entities = store.Query(query => Filter(query, filter).OrderBy(orderBy)).Paginate(pageArgs); |
| | 67 | 45 | | return Task.FromResult(entities); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public Task<IEnumerable<BookmarkQueueItem>> FindManyAsync(BookmarkQueueFilter filter, CancellationToken cancellation |
| | | 49 | | { |
| | 204 | 50 | | var entities = store.Query(query => Filter(query, filter)).AsEnumerable(); |
| | 102 | 51 | | return Task.FromResult(entities); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public async Task<long> DeleteAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 56 | | { |
| | 177 | 57 | | var ids = (await FindManyAsync(filter, cancellationToken)).Select(x => x.Id); |
| | 88 | 58 | | return store.DeleteMany(ids); |
| | 88 | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <remarks> |
| | | 62 | | /// Ambient tenant is applied here rather than in <see cref="BookmarkQueueFilter.Apply"/>. |
| | | 63 | | /// EF owns that via <c>SetTenantIdFilter</c> / <c>IgnoreQueryFilters</c>; Memory must compensate. |
| | | 64 | | /// </remarks> |
| | | 65 | | private IQueryable<BookmarkQueueItem> Filter(IQueryable<BookmarkQueueItem> query, BookmarkQueueFilter filter) => |
| | 176 | 66 | | filter.Apply(query.WhereVisibleToTenant(CurrentTenantId, filter.TenantAgnostic)); |
| | | 67 | | |
| | 332 | 68 | | private string CurrentTenantId => tenantAccessor?.TenantId ?? Tenant.DefaultTenantId; |
| | | 69 | | } |