From a186947319b449c0cb2b2f619365cd235d861d44 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 4 Nov 2022 18:36:51 -0500 Subject: add Hosts to state --- src/slskd/Core/State.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/slskd/Core/State.cs b/src/slskd/Core/State.cs index 519f5345..f3fbf03e 100644 --- a/src/slskd/Core/State.cs +++ b/src/slskd/Core/State.cs @@ -106,6 +106,7 @@ namespace slskd public bool Faulted { get; init; } public bool Cancelled { get; init; } public double ScanProgress { get; init; } + public IReadOnlyCollection Hosts { get; init; } public int Directories { get; init; } public int Files { get; init; } } -- cgit v1.2.3 From 936459e44baed4a588327677b920d33ab8246b71 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 4 Nov 2022 18:37:11 -0500 Subject: update Hosts when they change --- src/slskd/Shares/ShareService.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index a497012f..76bce57c 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -131,6 +131,7 @@ namespace slskd.Shares State.SetValue(state => state with { + Hosts = Hosts.Select(host => host.Name).ToArray(), Directories = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), Files = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), }); @@ -244,6 +245,7 @@ namespace slskd.Shares { State.SetValue(state => state with { + Hosts = Hosts.Select(host => host.Name).ToList().AsReadOnly(), Directories = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), Files = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), }); @@ -432,6 +434,7 @@ namespace slskd.Shares Faulted = false, Ready = true, ScanProgress = 1, + Hosts = Hosts.Select(host => host.Name).ToList().AsReadOnly(), Directories = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), Files = Hosts.Sum(host => host.Shares.Sum(share => share.Directories)), }); -- cgit v1.2.3 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(-) (limited to 'src') 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