Class Recalculator
Recalculates persistent calculated attributes en masse.
public sealed class Recalculator
- Inheritance
-
Recalculator
- Inherited Members
Remarks
Each type is recalculated in batches, which are ordered ranges of IDs, loaded in one round trip along with the related entities derived from [CalculationDependency] and [CalculationResult] declarations on methods and hooks. Only the batch type's entities are calculated; they are saved with SaveNodesAsync(IEnumerable<EntityKernel>, IEntityContext, CancellationToken?), without running save hooks. Calculation hooks do run, with Batch; [CalculationResult]s of the hooks are also saved, but anything else that caught a stray update is just logged as a warning.
Types are grouped into strongly connected components using Tarjan's algorithm, then the groups are sorted based on dependencies; independent batches run concurrently (up to The.Import.GroupScheduler's limit). Cycles are recalculated repeatedly in the hope of reaching a stable equilibrium.
Constructors
Recalculator(PersistenceService, EntityMetadataDictionary, ILogger, RecalculatorOptions)
public Recalculator(PersistenceService persistence, EntityMetadataDictionary metadata, ILogger logger, RecalculatorOptions options)
Parameters
persistencePersistenceServicemetadataEntityMetadataDictionaryloggerILoggeroptionsRecalculatorOptions
Methods
RecalculateAsync(Func<IEntityContext>, IEnumerable<IEntityInfo>, IProgress<Status>?, CancellationToken)
public Task<IReadOnlyList<EntityCalculationResult>> RecalculateAsync(Func<IEntityContext> createContext, IEnumerable<IEntityInfo> types, IProgress<Status>? progress, CancellationToken cancellationToken = default)
Parameters
createContextFunc<IEntityContext>typesIEnumerable<IEntityInfo>progressIProgress<Status>cancellationTokenCancellationToken