aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Application.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-08-16 15:06:25 -0500
committerGitHub <noreply@github.com>2025-08-16 15:06:25 -0500
commitb08c877124a29fbdc34ae5fea8839006e307810b (patch)
treef058d1cdb7821aec539cf3c11f67812627108293 /src/slskd/Application.cs
parent52a7fa8141e5f11b95175f68dbd8fc3070636e3c (diff)
parent5b0c4b7a42c22164635efa2558131075e725dcf4 (diff)
downloadslskd-b08c877124a29fbdc34ae5fea8839006e307810b.tar.gz
Merge branch 'master' into metrics
Diffstat (limited to 'src/slskd/Application.cs')
-rw-r--r--src/slskd/Application.cs30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 41597396..d8dab87c 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -135,7 +135,10 @@ namespace slskd
regexOptions |= RegexOptions.IgnoreCase;
}
- CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions));
+ CompiledSearchRequestFilters = OptionsAtStartup.Filters.Search.Request
+ .Select(f => new Regex(f, regexOptions))
+ .ToList()
+ .AsReadOnly();
State = state;
State.OnChange(state => State_OnChange(state));
@@ -228,10 +231,10 @@ namespace slskd
private ISearchService Search { get; set; }
private IRelayService Relay { get; set; }
private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions());
- private IEnumerable<Regex> CompiledSearchResponseFilters { get; set; }
- private IEnumerable<Guid> ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty<Guid>();
+ private IReadOnlyList<Regex> CompiledSearchRequestFilters { get; set; } = [];
+ private IReadOnlyList<Guid> ActiveDownloadIdsAtPreviousShutdown { get; set; } = [];
private Options.FlagsOptions Flags { get; set; }
- private IReadOnlyCollection<string> ExcludedSearchPhrases { get; set; } = Enumerable.Empty<string>().ToList();
+ private IReadOnlyList<string> ExcludedSearchPhrases { get; set; } = [];
public void CollectGarbage()
{
@@ -352,7 +355,7 @@ namespace slskd
// save the ids of any downloads that were active, so we can re-enqueue them after we've connected and logged in.
// we need to check the database before we re-request to make sure the user didn't remove them from the UI while
// the application was running, but before it was logged in. so just save the ids.
- ActiveDownloadIdsAtPreviousShutdown = activeDownloads.Select(d => d.Id);
+ ActiveDownloadIdsAtPreviousShutdown = activeDownloads.Select(d => d.Id).ToList().AsReadOnly();
Log.Debug("Downloads to resume upon connection: {Ids}", ActiveDownloadIdsAtPreviousShutdown.ToJson());
Log.Debug("Configuring client");
@@ -924,7 +927,7 @@ namespace slskd
}
// clear the ids we saved at startup; we don't want to re-request these again if the connection is cycled
- ActiveDownloadIdsAtPreviousShutdown = Enumerable.Empty<Guid>();
+ ActiveDownloadIdsAtPreviousShutdown = [];
}
catch (Exception ex)
{
@@ -1178,7 +1181,7 @@ namespace slskd
private void Client_ExcludedSearchPhrasesReceived(object sender, IReadOnlyCollection<string> e)
{
Log.Debug("Excluded search phrases: {Phrases}", string.Join(", ", e));
- ExcludedSearchPhrases = e;
+ ExcludedSearchPhrases = e.ToList();
}
private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args)
@@ -1270,6 +1273,8 @@ namespace slskd
// shenanigans here could lead to missed updates.
await OptionsSyncRoot.WaitAsync();
+ Log.Debug("OptionsMonitor OnChange Invoked");
+
try
{
var pendingRestart = false;
@@ -1281,9 +1286,12 @@ namespace slskd
// don't react to duplicate/no-change events https://github.com/slskd/slskd/issues/126
if (!diff.Any())
{
+ Log.Debug("Diff of previous and new options is the same; nothing to do");
return;
}
+ Log.Debug("Diff of previous and new options contains {Count} changed properties: {Properties}", diff.Count(), diff.Select(p => p.FQN));
+
foreach (var (property, fqn, left, right) in diff)
{
static bool HasAttribute<T>(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T));
@@ -1314,7 +1322,11 @@ namespace slskd
if (PreviousOptions.Filters.Search.Request.Except(newOptions.Filters.Search.Request).Any()
|| newOptions.Filters.Search.Request.Except(PreviousOptions.Filters.Search.Request).Any())
{
- CompiledSearchResponseFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled));
+ CompiledSearchRequestFilters = newOptions.Filters.Search.Request
+ .Select(f => new Regex(f, RegexOptions.Compiled))
+ .ToList()
+ .AsReadOnly();
+
Log.Information("Updated and re-compiled search response filters");
}
@@ -1440,7 +1452,7 @@ namespace slskd
return null;
}
- if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText)))
+ if (CompiledSearchRequestFilters.Any(filter => filter.IsMatch(query.SearchText)))
{
return null;
}