45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
using Explorer.Domain;
|
|
|
|
namespace Explorer.Application;
|
|
|
|
public static class BackgroundMaintenancePlanner
|
|
{
|
|
public static Source? NextLocalScan(
|
|
IEnumerable<Source> sources,
|
|
DateTimeOffset utc,
|
|
IReadOnlySet<long>? alreadyQueued = null)
|
|
{
|
|
var cutoff = utc - TimeSpan.FromDays(AppConstants.IdleRescanAfterDays);
|
|
return EligibleLocal(sources, alreadyQueued)
|
|
.Where(source => source.Status == SourceStatus.Stale
|
|
|| source.LastIndexedUtc is null
|
|
|| source.LastIndexedUtc < cutoff)
|
|
.OrderBy(source => source.Status == SourceStatus.Stale ? 0 : 1)
|
|
.ThenBy(source => source.LastIndexedUtc ?? DateTimeOffset.MinValue)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public static Source? NextLocalVerify(
|
|
IEnumerable<Source> sources,
|
|
IReadOnlySet<long>? alreadyQueued = null)
|
|
=> EligibleLocal(sources, alreadyQueued)
|
|
.OrderBy(source => source.Status == SourceStatus.Stale ? 0 : 1)
|
|
.ThenBy(source => source.LastIndexedUtc ?? DateTimeOffset.MinValue)
|
|
.FirstOrDefault();
|
|
|
|
public static Source? NextHashCollisionSource(
|
|
IEnumerable<Source> sources,
|
|
IReadOnlySet<long>? alreadyEnqueued = null)
|
|
=> EligibleLocal(sources, alreadyEnqueued)
|
|
.OrderBy(source => source.LastIndexedUtc ?? DateTimeOffset.MinValue)
|
|
.FirstOrDefault();
|
|
|
|
private static IEnumerable<Source> EligibleLocal(IEnumerable<Source> sources, IReadOnlySet<long>? skip)
|
|
=> sources.Where(source =>
|
|
source.Kind == SourceKind.NtfsLocal
|
|
&& source.IsIndexed
|
|
&& source.Status is SourceStatus.Online or SourceStatus.Stale
|
|
&& !string.IsNullOrWhiteSpace(source.LastRootPath)
|
|
&& (skip is null || !skip.Contains(source.Id)));
|
|
}
|