diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-09-07 12:19:04 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-09-07 12:19:04 -0500 |
| commit | 032e31e2aa04a9d5a0ee2a3ebeb120a63e720854 (patch) | |
| tree | 850b28039fed47140a487667f1d1a6a2b186fd88 /src/slskd/Shares | |
| parent | 5d33e56bc35aa809b98bdf98e0b13e6c0dd04541 (diff) | |
| download | slskd-032e31e2aa04a9d5a0ee2a3ebeb120a63e720854.tar.gz | |
move share resolution out of the loop
Diffstat (limited to 'src/slskd/Shares')
| -rw-r--r-- | src/slskd/Shares/ShareScanner.cs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index 063dc0e4..af0b2181 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -272,6 +272,18 @@ namespace slskd.Shares var cached = 0; var filtered = 0; + // set up a function to reliably resolve the Share given a directory; users can define nested shares, + // so we need to sort to ensure the deepest-nested share is selected first + var sortedShares = Shares + .Where(s => !s.IsExcluded) + .OrderByDescending(s => s.LocalPath.Length) + .ToList(); + + Share ResolveShareFromDirectory(string directory) + { + return sortedShares.First(share => IsSubDirectoryOf(subDirectory: directory, root: share.LocalPath)); + } + // set up a channel to fan out for directory scanning var channel = Channel.CreateBounded<string>(new BoundedChannelOptions(1000) { @@ -286,15 +298,6 @@ namespace slskd.Shares foreach (var id in Enumerable.Range(0, WorkerCount)) { - // set up a function to reliably resolve the Share given a directory; users can define nested shares, - // so we need to sort to ensure the deepest-nested share is selected first - var sortedShares = Shares.OrderByDescending(s => s.LocalPath.Length); - - Share ResolveShareFromDirectory(string directory) - { - return sortedShares.First(share => IsSubDirectoryOf(subDirectory: directory, root: share.LocalPath)); - } - workers.Add(new ChannelReader<string>( channel: channel, cancellationToken: cancellationToken, |
