aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-07-16 18:01:56 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-07-16 18:01:56 -0500
commitf84f2498c1ef9bc8a0fc09a4848a1a5d27f8f22b (patch)
treeb4b52663719ebe0cdb7cf6985518d4e2fe998d18 /src
parent6bcab1af3c4cc3227f18192d14cbcecc13f40a94 (diff)
downloadslskd-f84f2498c1ef9bc8a0fc09a4848a1a5d27f8f22b.tar.gz
prevent updates after the search is concluded
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Search/SearchService.cs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs
index 45ad86db..9b30f26c 100644
--- a/src/slskd/Search/SearchService.cs
+++ b/src/slskd/Search/SearchService.cs
@@ -117,13 +117,22 @@ namespace slskd.Search
},
responseReceived: (args) => rateLimiter.Invoke(() =>
{
- // note: this is rate limited, but has the potential to update
- // the database every 250ms (or whatever the interval is set to)
- // for the duration of the search. any issues with disk/io or performance
- // while searches are running should investigate this as a cause
- search = search.WithSoulseekSearch(args.Search);
- SearchHub.BroadcastUpdateAsync(search);
- _ = UpdateAndSaveChangesAsync(search);
+ // due to the rate limiter, this has the potential to be executed after the search is complete.
+ // ensure that doesn't happen. this causes the update to be dropped, but we broadcast again when
+ // the search is complete with the final stats, so it has no negative impact.
+ if (search.State.HasFlag(SearchStates.InProgress))
+ {
+ // note: this is rate limited, but has the potential to update
+ // the database every 250ms (or whatever the interval is set to)
+ // for the duration of the search. any issues with disk/io or performance
+ // while searches are running should investigate this as a cause
+ search.ResponseCount = args.Search.ResponseCount;
+ search.FileCount = args.Search.FileCount;
+ search.LockedFileCount = args.Search.LockedFileCount;
+
+ SearchHub.BroadcastUpdateAsync(search);
+ _ = UpdateAndSaveChangesAsync(search);
+ }
}));
var soulseekSearchTask = Client.SearchAsync(