From f92ef3c7a13eeb65ded5a26fda2f261f120eb88e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 5 Nov 2022 13:26:58 -0500 Subject: only compute local shares --- src/slskd/Shares/IShareService.cs | 7 ------- src/slskd/Shares/ShareService.cs | 34 +++++++++++++++------------------- 2 files changed, 15 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index dff6a8ce..aea3240a 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -53,13 +53,6 @@ namespace slskd.Shares /// The entire contents of the share. Task> BrowseAsync(Share share = null); - /// - /// Gets statistical information for the specified . - /// - /// The share to summarize. - /// The summary information. - Task<(int Directories, int Files)> ComputeShareStatisticsAsync(Share share); - /// /// Dumps the local share cache to a file. /// diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 76bce57c..109c9593 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -188,23 +188,6 @@ namespace slskd.Shares return Task.FromResult(results); } - /// - /// Gets summary information for the specified . - /// - /// The share to summarize. - /// The summary information. - public Task<(int Directories, int Files)> ComputeShareStatisticsAsync(Share share) - { - var prefix = share.RemotePath + (share.RemotePath.EndsWith('\\') ? string.Empty : '\\'); - - var dirs = AllRepositories.Select(r => r.CountDirectories(prefix)).Sum(); - var files = AllRepositories.Select(r => r.CountFiles(prefix)).Sum(); - - share.UpdateStatistics(dirs, files); - - return Task.FromResult((dirs, files)); - } - /// /// Dumps the local share cache to a file. /// @@ -336,7 +319,7 @@ namespace slskd.Shares Log.Debug("Shared file cache database backup complete"); Log.Debug("Recomputing share statistics..."); - await Task.WhenAll(Local.Host.Shares.Select(share => ComputeShareStatisticsAsync(share))); + ComputeShareStatistics(); Log.Debug("Share statistics updated"); } @@ -418,7 +401,7 @@ namespace slskd.Shares Local.Repository.EnableKeepalive(true); Log.Debug("Recomputing share statistics..."); - await Task.WhenAll(Local.Host.Shares.Select(share => ComputeShareStatisticsAsync(share))); + ComputeShareStatistics(); Log.Debug("Share statistics updated"); // one of several thigns happened above before we got here: @@ -456,6 +439,19 @@ namespace slskd.Shares } } + private void ComputeShareStatistics() + { + foreach (var share in Local.Host.Shares) + { + var prefix = share.RemotePath + (share.RemotePath.EndsWith('\\') ? string.Empty : '\\'); + + var dirs = Local.Repository.CountDirectories(prefix); + var files = Local.Repository.CountFiles(prefix); + + share.UpdateStatistics(dirs, files); + } + } + private void Configure(Options options) { SyncRoot.Wait(); -- cgit v1.2.3