aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-04-28 22:42:13 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-04-28 22:42:13 -0500
commit3e5126630c88aae010c0d91f0f2597c1815fb5e7 (patch)
tree790bc3d064f0aecfc65ee12fb36ca659d8e8e474 /src
parent938b3ad1f34b671fc967849bd668610838e499d3 (diff)
downloadslskd-3e5126630c88aae010c0d91f0f2597c1815fb5e7.tar.gz
rate limit updates
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Search/SearchService.cs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs
index afbfe0fb..7eda0f0b 100644
--- a/src/slskd/Search/SearchService.cs
+++ b/src/slskd/Search/SearchService.cs
@@ -94,20 +94,21 @@ namespace slskd.Search
StartedAt = DateTime.Now,
};
+ var rateLimiter = new RateLimiter(250);
+
options ??= new SearchOptions();
options = options.WithActions(
stateChanged: (args) => SearchHub.BroadcastUpdateAsync(search.WithSoulseekSearch(args.Search)),
- responseReceived: (args) => SearchHub.BroadcastUpdateAsync(search.WithSoulseekSearch(args.Search)));
+ responseReceived: (args) => rateLimiter.Invoke(() => SearchHub.BroadcastUpdateAsync(search.WithSoulseekSearch(args.Search))));
using var context = ContextFactory.CreateDbContext();
-
context.Add(search);
await context.SaveChangesAsync();
- await SearchHub.BroadcastCreateAsync(search);
-
CancellationTokens.TryAdd(id, cancellationTokenSource);
+ await SearchHub.BroadcastCreateAsync(search);
+
_ = Task.Run(async () =>
{
var (soulseekSearch, responses) = await Client.SearchAsync(
@@ -117,9 +118,11 @@ namespace slskd.Search
options,
cancellationToken: cancellationTokenSource.Token);
+ rateLimiter.Dispose();
CancellationTokens.TryRemove(id, out _);
search = search.WithSoulseekSearch(soulseekSearch);
+ await SearchHub.BroadcastUpdateAsync(search);
search.Responses = responses.Select(r => Response.FromSoulseekSearchResponse(r));
using var context = ContextFactory.CreateDbContext();