aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Shares/API/Controllers/SharesController.cs2
-rw-r--r--src/slskd/Shares/IShareService.cs5
-rw-r--r--src/slskd/Shares/ShareService.cs14
-rw-r--r--src/slskd/Shares/SharedFileCache.cs20
-rw-r--r--src/slskd/State.cs9
5 files changed, 42 insertions, 8 deletions
diff --git a/src/slskd/Shares/API/Controllers/SharesController.cs b/src/slskd/Shares/API/Controllers/SharesController.cs
index 8ae8551f..41178bac 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.Shares.Select(share =>
+ var summary = Shares.CachedShares.Select(share =>
{
var directories = browse.Where(directory => directory.Name.StartsWith(share.RemotePath));
var fileCount = directories.Aggregate(seed: 0, (sum, directory) =>
diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs
index 16f1a890..fd88f2b0 100644
--- a/src/slskd/Shares/IShareService.cs
+++ b/src/slskd/Shares/IShareService.cs
@@ -27,6 +27,11 @@ namespace slskd.Shares
public interface IShareService
{
/// <summary>
+ /// Gets the list of shares stored in the cache.
+ /// </summary>
+ IReadOnlyList<Share> CachedShares { get; }
+
+ /// <summary>
/// Gets the list of configured shares.
/// </summary>
IReadOnlyList<Share> Shares { get; }
diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs
index 9cae0d42..ead96d10 100644
--- a/src/slskd/Shares/ShareService.cs
+++ b/src/slskd/Shares/ShareService.cs
@@ -55,6 +55,11 @@ namespace slskd.Shares
Directories = current.Directories,
Files = current.Files,
});
+
+ if (previous.Filling && !current.Filling)
+ {
+ CachedShares = current.Shares.ToList().AsReadOnly();
+ }
});
OptionsMonitor = optionsMonitor;
@@ -68,7 +73,10 @@ namespace slskd.Shares
/// </summary>
public IReadOnlyList<Share> Shares => SharesList.AsReadOnly();
- public IReadOnlyList<Regex> FilterRegexes => FilterRegexList.AsReadOnly();
+ /// <summary>
+ /// Gets the list of shares stored in the cache.
+ /// </summary>
+ public IReadOnlyList<Share> CachedShares { get; private set; } = new List<Share>().AsReadOnly();
/// <summary>
/// Gets the state monitor for the service.
@@ -81,7 +89,7 @@ namespace slskd.Shares
private List<Share> SharesList { get; set; } = new List<Share>();
private IManagedState<ShareState> State { get; } = new ManagedState<ShareState>();
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1);
- private List<Regex> FilterRegexList { get; set; } = new List<Regex>();
+ private List<Regex> FilterRegexes { get; set; } = new List<Regex>();
/// <summary>
/// Returns the entire contents of the share.
@@ -160,7 +168,7 @@ namespace slskd.Shares
.ToList();
SharesList = shares;
- FilterRegexList = regexes;
+ FilterRegexes = regexes;
State.SetValue(state => state with { ScanPending = true });
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs
index 8ac52462..6b7a3ca3 100644
--- a/src/slskd/Shares/SharedFileCache.cs
+++ b/src/slskd/Shares/SharedFileCache.cs
@@ -175,7 +175,14 @@ namespace slskd.Shares
try
{
- State.SetValue(state => state with { Filling = true, Filled = false, FillProgress = 0 });
+ State.SetValue(state => state with
+ {
+ Filling = true,
+ Filled = false,
+ FillProgress = 0,
+ Shares = Enumerable.Empty<Share>().ToList().AsReadOnly(),
+ });
+
Log.Debug("Starting shared file scan");
await Task.Yield();
@@ -291,7 +298,16 @@ namespace slskd.Shares
MaskedDirectories = maskedDirectories;
MaskedFiles = files;
- State.SetValue(state => state with { Filling = false, Faulted = false, Filled = true, FillProgress = 1, Directories = MaskedDirectories.Count, Files = MaskedFiles.Count });
+ State.SetValue(state => state with {
+ Filling = false,
+ Faulted = false,
+ Filled = true,
+ 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}");
}
catch (Exception ex)
diff --git a/src/slskd/State.cs b/src/slskd/State.cs
index 407aeb9e..10ed80f6 100644
--- a/src/slskd/State.cs
+++ b/src/slskd/State.cs
@@ -21,6 +21,7 @@ namespace slskd
using System.Collections.Generic;
using System.Net;
using System.Text.Json.Serialization;
+ using slskd.Shares;
using slskd.Users;
using Soulseek;
@@ -32,7 +33,6 @@ namespace slskd
public VersionState Version { get; init; } = new VersionState();
public bool PendingReconnect { get; init; }
public bool PendingRestart { get; init; }
- public bool PendingShareRescan { get; init; }
public ServerState Server { get; init; } = new ServerState();
public DistributedNetworkState DistributedNetwork { get; init; } = new DistributedNetworkState();
public ShareState Shares { get; init; } = new ShareState();
@@ -69,7 +69,7 @@ namespace slskd
public string BranchRoot { get; init; }
public bool CanAcceptChildren { get; init; }
public int ChildLimit { get; init; }
- public IReadOnlyCollection<string> Children { get; init; }
+ public IReadOnlyCollection<string> Children { get; init; } = new List<string>().AsReadOnly();
public bool HasParent { get; init; }
public bool IsBranchRoot { get; init; }
public string Parent { get; init; }
@@ -124,5 +124,10 @@ namespace slskd
/// Gets the number of directories excluded by filters.
/// </summary>
public int ExcludedDirectories { get; init; }
+
+ /// <summary>
+ /// Gets the list of shares stored in the cache.
+ /// </summary>
+ public IReadOnlyCollection<Share> Shares { get; init; } = new List<Share>().AsReadOnly();
}
} \ No newline at end of file