From f84f2498c1ef9bc8a0fc09a4848a1a5d27f8f22b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 16 Jul 2022 18:01:56 -0500 Subject: prevent updates after the search is concluded --- src/slskd/Search/SearchService.cs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src') 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( -- cgit v1.2.3