From 6f79ad6b6d2bed8fd88c43aadc621e407ad60449 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 23 Aug 2022 08:07:07 -0500 Subject: remove shares from state --- src/slskd/Core/State.cs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Core/State.cs b/src/slskd/Core/State.cs index e009805a..a1da2be8 100644 --- a/src/slskd/Core/State.cs +++ b/src/slskd/Core/State.cs @@ -21,7 +21,6 @@ namespace slskd using System.Collections.Generic; using System.Net; using System.Text.Json.Serialization; - using slskd.Shares; using slskd.Users; using Soulseek; @@ -145,10 +144,5 @@ namespace slskd /// Gets the number of directories excluded by filters. /// public int ExcludedDirectories { get; init; } - - /// - /// Gets the list of shares stored in the cache. - /// - public IReadOnlyCollection Shares { get; init; } = new List().AsReadOnly(); } } \ No newline at end of file -- cgit v1.2.3 From 87c0d6625a1e8ad39be3035c7139116121cc15e4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 23 Aug 2022 08:07:23 -0500 Subject: use configured shares instead of cached --- src/slskd/Shares/API/Controllers/SharesController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd') diff --git a/src/slskd/Shares/API/Controllers/SharesController.cs b/src/slskd/Shares/API/Controllers/SharesController.cs index 56023925..12a1c7b2 100644 --- a/src/slskd/Shares/API/Controllers/SharesController.cs +++ b/src/slskd/Shares/API/Controllers/SharesController.cs @@ -59,7 +59,7 @@ namespace slskd.Shares.API { var browse = await Shares.BrowseAsync(); - var summary = Shares.CachedShares.Select(share => + var summary = Shares.Shares.Select(share => { var directories = browse.Where(directory => directory.Name.StartsWith(share.RemotePath)); var fileCount = directories.Aggregate(seed: 0, (sum, directory) => -- cgit v1.2.3 From e760fb9c7f22a9f67915bffbb6bb9c9b2e13fa37 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 23 Aug 2022 08:07:42 -0500 Subject: remove CachedShares --- src/slskd/Shares/IShareService.cs | 5 ----- src/slskd/Shares/ShareService.cs | 10 ---------- 2 files changed, 15 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index fd88f2b0..16f1a890 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -26,11 +26,6 @@ namespace slskd.Shares /// public interface IShareService { - /// - /// Gets the list of shares stored in the cache. - /// - IReadOnlyList CachedShares { get; } - /// /// Gets the list of configured shares. /// diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 169f6fff..60fbdda3 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -55,11 +55,6 @@ namespace slskd.Shares Directories = current.Directories, Files = current.Files, }); - - if (previous.Filling && !current.Filling) - { - CachedShares = current.Shares.ToList().AsReadOnly(); - } }); OptionsMonitor = optionsMonitor; @@ -73,11 +68,6 @@ namespace slskd.Shares /// public IReadOnlyList Shares => SharesList.AsReadOnly(); - /// - /// Gets the list of shares stored in the cache. - /// - public IReadOnlyList CachedShares { get; private set; } = new List().AsReadOnly(); - /// /// Gets the state monitor for the service. /// -- cgit v1.2.3 From a81fde8c29be4b99d66c24006d191232b72d9e7c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 23 Aug 2022 08:08:51 -0500 Subject: more verbose logging, capture state exception --- src/slskd/Shares/SharedFileCache.cs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index 3b3f7eae..ba07067b 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -180,7 +180,6 @@ namespace slskd.Shares Filling = true, Filled = false, FillProgress = 0, - Shares = Enumerable.Empty().ToList().AsReadOnly(), }); Log.Debug("Starting shared file scan"); @@ -247,11 +246,16 @@ namespace slskd.Shares var files = new Dictionary(); var maskedDirectories = new HashSet(); - var current = 0; - var filtered = 0; + var current = 0L; + var filtered = 0L; foreach (var directory in unmaskedDirectories) { + Log.Debug("Starting scan of {Directory} ({Current}/{Total})", directory, current + 1, unmaskedDirectories.Count); + + var addedFiles = 0L; + var filteredFiles = 0L; + var share = Shares.First(share => directory.StartsWith(share.LocalPath)); maskedDirectories.Add(directory.ReplaceFirst(share.LocalPath, share.RemotePath)); @@ -271,13 +275,15 @@ namespace slskd.Shares .Select(filename => SoulseekFileFactory.Create(filename, maskedFilename: filename.ReplaceFirst(share.LocalPath, share.RemotePath))) .ToDictionary(file => file.Filename, file => file); + addedFiles = newFiles.Count; + // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully // qualified name the only time this *should* cause problems is if one of the shares is a subdirectory of another. foreach (var file in newFiles) { if (filters.Any(filter => filter.IsMatch(file.Key))) { - filtered++; + filteredFiles++; continue; } @@ -296,7 +302,19 @@ namespace slskd.Shares } current++; - State.SetValue(state => state with { FillProgress = current / (double)unmaskedDirectories.Count, Files = files.Count }); + filtered += filteredFiles; + + Log.Debug("Finished scanning {Directory}: {Added} files added and {Filtered} filtered", directory, addedFiles, filteredFiles); + + try + { + State.SetValue(state => state with { FillProgress = current / (double)unmaskedDirectories.Count, Files = files.Count }); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to set cache state following scan of {Directory}: {Message}", directory, ex.Message); + throw; + } } Log.Debug("Directory scan found {Files} files (and {Filtered} were filtered) in {Elapsed}ms. Populating filename database", files.Count, filtered, sw.ElapsedMilliseconds - swSnapshot); @@ -321,7 +339,6 @@ namespace slskd.Shares FillProgress = 1, Directories = MaskedDirectories.Count, Files = MaskedFiles.Count, - Shares = shares.ToList().AsReadOnly(), }); Log.Debug($"Shared file cache recreated in {sw.ElapsedMilliseconds}ms. Directories: {unmaskedDirectories.Count}, Files: {files.Count}"); -- cgit v1.2.3 From b45b8cc62be35b63af5544b746b4ce556d258e78 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 23 Aug 2022 08:09:03 -0500 Subject: tweak share scanning progress logging --- src/slskd/Application.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 5a56e110..ed3aec30 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -965,10 +965,10 @@ namespace slskd var lastProgress = Math.Round(previous.ScanProgress * 100); var currentProgress = Math.Round(current.ScanProgress * 100); - if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 10d == 0) + if (lastProgress != currentProgress && Math.Round(currentProgress, 0) % 5d == 0) { State.SetValue(s => s with { Shares = current }); - Log.Information("Scanned {Percent}% () of shared directories. Found {Files} files so far.", currentProgress, current.Files); + Log.Information("Scanned {Percent}% of shared directories. Found {Files} files so far.", currentProgress, current.Files); } } } -- cgit v1.2.3