diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-03-13 17:46:36 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-03-13 17:46:36 -0500 |
| commit | 3fa9c6f1a0ae11a45475e7681372154a23a844f3 (patch) | |
| tree | 436ff3e42d75a2da2399f1b53d02efdc48255389 /src | |
| parent | 8dddf66d1372d913ac81374af0a0e0b47e49b157 (diff) | |
| download | slskd-3fa9c6f1a0ae11a45475e7681372154a23a844f3.tar.gz | |
move setup into try
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Search/SearchService.cs | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index b4864918..e0466043 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -1,4 +1,4 @@ -// <copyright file="SearchService.cs" company="slskd Team"> +// <copyright file="SearchService.cs" company="slskd Team"> // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -239,41 +239,41 @@ namespace slskd.Search StartedAt = DateTime.UtcNow, }; - using var context = ContextFactory.CreateDbContext(); - context.Add(search); - context.SaveChanges(); + try + { + using var context = ContextFactory.CreateDbContext(); + context.Add(search); + context.SaveChanges(); - await SearchHub.BroadcastCreateAsync(search); + await SearchHub.BroadcastCreateAsync(search); - // initialize the list of responses that we'll use to accumulate them - // populated by the responseHandler we pass to SearchAsync - List<SearchResponse> responses = new(); + // initialize the list of responses that we'll use to accumulate them + // populated by the responseHandler we pass to SearchAsync + List<SearchResponse> responses = new(); - options ??= new SearchOptions(); - options = options.WithActions( - stateChanged: (args) => - { - search = search.WithSoulseekSearch(args.Search); - SearchHub.BroadcastUpdateAsync(search); - Update(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 i/o 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; - - // note that we're not actually doing anything with the response here, that's happening in the - // response handler. we're only updating counts here. - SearchHub.BroadcastUpdateAsync(search); - Update(search); - })); + options ??= new SearchOptions(); + options = options.WithActions( + stateChanged: (args) => + { + search = search.WithSoulseekSearch(args.Search); + SearchHub.BroadcastUpdateAsync(search); + Update(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 i/o 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; + + // note that we're not actually doing anything with the response here, that's happening in the + // response handler. we're only updating counts here. + SearchHub.BroadcastUpdateAsync(search); + Update(search); + })); - try - { // initiate the search. this can throw at invocation if there's a problem with // the client state (e.g. disconnected) or a problem with the search (e.g. no terms) var soulseekSearchTask = Client.SearchAsync( |
