From a2a4a0c7fbe9630ff0a94ea75a6fbef1dcfa143f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 4 Nov 2022 18:37:28 -0500 Subject: rebuild browse cache when hosts change --- src/slskd/Application.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 68f0276b..8aaa0470 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -996,6 +996,7 @@ namespace slskd private void ShareState_OnChange((ShareState Previous, ShareState Current) state) { var (previous, current) = state; + bool rebuildBrowseCache = false; if (!previous.Scanning && current.Scanning) { @@ -1019,7 +1020,7 @@ namespace slskd { State.SetValue(state => state with { Shares = state.Shares with { ScanPending = false } }); Log.Information("Shares scanned successfully. Found {Directories} directories and {Files} files in {Duration}ms", current.Directories, current.Files, (DateTime.UtcNow - SharesRefreshStarted).TotalMilliseconds); - _ = CacheBrowseResponse(); + rebuildBrowseCache = true; SharesRefreshStarted = default; @@ -1038,7 +1039,7 @@ namespace slskd // the share transitioned into ready without completing a scan; it was loaded from disk State.SetValue(state => state with { Shares = current with { ScanPending = false } }); Log.Information("Share cache loaded from disk successfully. Sharing {Directories} directories and {Files} files", current.Directories, current.Files); - _ = CacheBrowseResponse(); + rebuildBrowseCache = true; } else { @@ -1052,6 +1053,11 @@ namespace slskd Log.Information("Scanned {Percent}% of shared directories. Found {Files} files so far.", currentProgress, current.Files); } } + + if (rebuildBrowseCache || previous.Hosts.ToJson() != current.Hosts.ToJson()) + { + _ = CacheBrowseResponse(); + } } private async Task CacheBrowseResponse() -- cgit v1.2.3