aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-01-20 20:40:12 -0600
committerJP Dillingham <jp@dillingham.me>2025-01-20 20:40:12 -0600
commit71d8c3d233458fde02d7b169380ad347aaf88342 (patch)
tree40c384a559d7482c9b864aa38a0855ff93016992 /src
parent2950b16e08e4c18edb03bba299baef1faf7cb6f3 (diff)
downloadslskd-71d8c3d233458fde02d7b169380ad347aaf88342.tar.gz
add a public Update() method, refactor to use it internally
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Search/SearchService.cs33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs
index 809647b2..f91714f5 100644
--- a/src/slskd/Search/SearchService.cs
+++ b/src/slskd/Search/SearchService.cs
@@ -65,6 +65,15 @@ namespace slskd.Search
Task<List<Search>> ListAsync(Expression<Func<Search, bool>> expression = null);
/// <summary>
+ /// Updates the specified <paramref name="search"/>.
+ /// </summary>
+ /// <remark>
+ /// Round-trips the database; use accordingly.
+ /// </remark>
+ /// <param name="search">The search to update.</param>
+ void Update(Search search);
+
+ /// <summary>
/// Performs a search for the specified <paramref name="query"/> and <paramref name="scope"/>.
/// </summary>
/// <param name="id">A unique identifier for the search.</param>
@@ -192,6 +201,17 @@ namespace slskd.Search
}
/// <summary>
+ /// Updates the specified <paramref name="search"/>.
+ /// </summary>
+ /// <param name="search">The search to update.</param>
+ public void Update(Search search)
+ {
+ using var context = ContextFactory.CreateDbContext();
+ context.Update(search);
+ context.SaveChanges();
+ }
+
+ /// <summary>
/// Performs a search for the specified <paramref name="query"/> and <paramref name="scope"/>.
/// </summary>
/// <param name="id">A unique identifier for the search.</param>
@@ -223,20 +243,13 @@ namespace slskd.Search
List<SearchResponse> responses = new();
- void UpdateAndSaveChanges(Search search)
- {
- using var context = ContextFactory.CreateDbContext();
- context.Update(search);
- context.SaveChanges();
- }
-
options ??= new SearchOptions();
options = options.WithActions(
stateChanged: (args) =>
{
search = search.WithSoulseekSearch(args.Search);
SearchHub.BroadcastUpdateAsync(search);
- UpdateAndSaveChanges(search);
+ Update(search);
},
responseReceived: (args) => rateLimiter.Invoke(() =>
{
@@ -250,7 +263,7 @@ namespace slskd.Search
// 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);
- UpdateAndSaveChanges(search);
+ Update(search);
}));
var soulseekSearchTask = Client.SearchAsync(
@@ -278,7 +291,7 @@ namespace slskd.Search
search.EndedAt = DateTime.UtcNow;
search.Responses = responses.Select(r => Response.FromSoulseekSearchResponse(r));
- UpdateAndSaveChanges(search);
+ Update(search);
// zero responses before broadcasting, as we don't want to blast this
// data out over the SignalR socket