aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Application.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-08-07 15:57:13 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-08-07 15:57:13 -0500
commit80ecb0d03cf1da83e33dde6326365713b3d605e0 (patch)
treedd8ea1392c4f61defc67b6436ee58be689b3991b /src/slskd/Application.cs
parent9a51c7fcc0f7a0394b7c3e5cdc01322652743470 (diff)
parent25c4abfc9428272eed0936d17c8a310653b21111 (diff)
downloadslskd-80ecb0d03cf1da83e33dde6326365713b3d605e0.tar.gz
Merge remote-tracking branch 'origin/master' into transfers
Diffstat (limited to 'src/slskd/Application.cs')
-rw-r--r--src/slskd/Application.cs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 3e501cdc..44723aba 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -29,6 +29,7 @@ namespace slskd
using System.Net.Sockets;
using System.Reflection;
using System.Runtime;
+ using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -112,6 +113,8 @@ namespace slskd
PreviousOptions = OptionsMonitor.CurrentValue;
+ CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled));
+
State = state;
State.OnChange(state => State_OnChange(state));
@@ -187,6 +190,7 @@ namespace slskd
private IUserService Users { get; set; }
private IShareService Shares { 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>();
public void CollectGarbage()
@@ -199,7 +203,7 @@ namespace slskd
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
#pragma warning disable S1215 // "GC.Collect" should not be called
- GC.Collect(2, GCCollectionMode.Forced, blocking: false, compacting: true);
+ GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true);
#pragma warning restore S1215 // "GC.Collect" should not be called
sw.Stop();
@@ -740,6 +744,13 @@ namespace slskd
Log.Information("File filter configuration changed. Shares must be re-scanned for changes to take effect.");
}
+ 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));
+ Log.Information("Updated and re-compiled search response filters");
+ }
+
if (PreviousOptions.Rooms.Except(newOptions.Rooms).Any()
|| newOptions.Rooms.Except(PreviousOptions.Rooms).Any())
{
@@ -861,8 +872,7 @@ namespace slskd
/// <returns>A Task resolving a SearchResponse, or null.</returns>
private async Task<SearchResponse> SearchResponseResolver(string username, int token, SearchQuery query)
{
- // some bots and perhaps users search for very short terms. only respond to queries >= 3 characters. sorry, U2 fans.
- if (query.Query.Length < 3)
+ if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText)))
{
return null;
}