aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-05 10:26:26 -0500
committerGitHub <noreply@github.com>2022-11-05 10:26:26 -0500
commitc9c5887012f6c0c5fcf9d0722187cff298f80dfb (patch)
tree17f3b2e79affb074d517ad5a47fc924ef7fe1a34 /src
parent38fd2895b45b5a0c0941fa03d0f22ad6a5097a22 (diff)
parentc6f6fe7b252fef9d29011e846d286b7c49c61f89 (diff)
downloadslskd-c9c5887012f6c0c5fcf9d0722187cff298f80dfb.tar.gz
Merge branch 'master' into deregister
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs10
-rw-r--r--src/slskd/Core/State.cs1
-rw-r--r--src/slskd/Shares/ShareService.cs3
3 files changed, 12 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<BrowseResponse> CacheBrowseResponse()
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<string> Hosts { get; init; }
public int Directories { get; init; }
public int Files { get; init; }
}
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)),
});