| | | 1 | | using Anichron.Core.Data.Repository; |
| | | 2 | | |
| | | 3 | | namespace Anichron.Core.Work; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// The deletions a request queues, in queue order: one per live storage config, by id, then one unscoped |
| | | 7 | | /// deletion for orphans of a config that no longer exists or of none. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class ProxyDeletionPlan |
| | | 10 | | { |
| | | 11 | | /// <summary>Deletions of every unprocessed orphan of the sweep, with no selection.</summary> |
| | | 12 | | /// <param name="sweepId">The sweep.</param> |
| | | 13 | | /// <param name="pendingConfigs">Each live config, null for none, that the sweep's unprocessed orphans name.</param> |
| | | 14 | | public static IReadOnlyList<ProxyDeletionPayload> ForAll(Guid sweepId, IEnumerable<Guid?> pendingConfigs) |
| | 4 | 15 | | => [.. InQueueOrder(pendingConfigs.Distinct(), config => config) |
| | 4 | 16 | | .Select(config => new ProxyDeletionPayload(sweepId, config, null))]; |
| | | 17 | | |
| | | 18 | | /// <summary>Deletions of the selected orphans, each holding the ids of its scope's orphans.</summary> |
| | | 19 | | /// <param name="sweepId">The sweep.</param> |
| | | 20 | | /// <param name="selected">The selected orphans and their live configs.</param> |
| | | 21 | | public static IReadOnlyList<ProxyDeletionPayload> ForSelection(Guid sweepId, IEnumerable<ProxyOrphanScope> selected) |
| | 5 | 22 | | => [.. InQueueOrder(selected.GroupBy(o => o.LiveStorageConfigId), group => group.Key) |
| | 5 | 23 | | .Select(group => new ProxyDeletionPayload(sweepId, group.Key, [.. group.Select(o => o.Id)]))]; |
| | | 24 | | |
| | | 25 | | private static IOrderedEnumerable<T> InQueueOrder<T>(IEnumerable<T> scopes, Func<T, Guid?> configOf) |
| | 9 | 26 | | => scopes.OrderBy(s => configOf(s) is null).ThenBy(configOf); |
| | | 27 | | } |