namespace MailSharp.MailClient.Services.Logging; public interface IBackgroundIndexingStatus { int MaxConcurrentIndexing { get; } int CurrentlyAvailableSlots { get; } IReadOnlyCollection InProgressKeys { get; } // Only populated while a key's index build is doing a full reindex (see // ImapService.EnsureFolderIndexedAsync) - returns false for keys still in InProgressKeys but // not yet past the initial connect/search step, or doing a cheap incremental sync instead. bool TryGetProgress(string key, out int processed, out int total); } // Thin read-only view over ImapService's process-wide static indexing state - that state is // already shared across every request (see ImapService.IndexingInProgress/ // BackgroundIndexingThrottle), so this just exposes it for the Maintenance page instead of // routing background indexing through a new service. public class BackgroundIndexingStatus : IBackgroundIndexingStatus { public int MaxConcurrentIndexing => ImapService.MaxConcurrentBackgroundIndexing; public int CurrentlyAvailableSlots => ImapService.BackgroundIndexingThrottle.CurrentCount; public IReadOnlyCollection InProgressKeys => [.. ImapService.IndexingInProgress.Keys]; public bool TryGetProgress(string key, out int processed, out int total) { if (ImapService.IndexingProgress.TryGetValue(key, out var progress)) { processed = progress.Processed; total = progress.Total; return true; } processed = 0; total = 0; return false; } }