Show folder names immediately and refresh stale index sizes without walking the whole drive.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
44
src/Explorer.Application/BackgroundMaintenancePlanner.cs
Normal file
44
src/Explorer.Application/BackgroundMaintenancePlanner.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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)));
|
||||
}
|
||||
Reference in New Issue
Block a user