From dbf9a8742745708d7d9da8f1de12e726f06bd7fc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 24 Jul 2022 13:12:07 -0500 Subject: docs --- src/slskd/Search/ISearchService.cs | 30 ++++----- src/slskd/Search/SearchService.cs | 131 ++++++++++++++++++------------------- 2 files changed, 79 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/slskd/Search/ISearchService.cs b/src/slskd/Search/ISearchService.cs index 9a45280b..4fe15fae 100644 --- a/src/slskd/Search/ISearchService.cs +++ b/src/slskd/Search/ISearchService.cs @@ -21,25 +21,13 @@ namespace slskd.Search using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; - using SearchOptions = Soulseek.SearchOptions; - using SearchQuery = Soulseek.SearchQuery; - using SearchScope = Soulseek.SearchScope; + using Soulseek; /// /// Handles the lifecycle and persistence of searches. /// public interface ISearchService { - /// - /// Performs a search for the specified and . - /// - /// A unique identifier for the search. - /// The search query. - /// The search scope. - /// Search options. - /// The completed search. - Task StartAsync(Guid id, SearchQuery query, SearchScope scope, SearchOptions options = null); - /// /// Deletes the specified ssearch. /// @@ -53,16 +41,26 @@ namespace slskd.Search /// The expression to use to match searches. /// A value indicating whether to include search responses in the result. /// The found search, or default if not found. - /// Thrown an expression is not supplied. + /// Thrown when an expression is not supplied. Task FindAsync(Expression> expression, bool includeResponses = false); /// - /// Returns a list of all completed and in-progress searches, with responses omitted. + /// Returns a list of all completed and in-progress searches, with responses omitted, matching the optional . /// /// An optional expression used to match searches. - /// The list of searches matching the specified expression. + /// The list of searches matching the specified expression, or all searches if no expression is specified. Task> ListAsync(Expression> expression = null); + /// + /// Performs a search for the specified and . + /// + /// A unique identifier for the search. + /// The search query. + /// The search scope. + /// Search options. + /// The completed search. + Task StartAsync(Guid id, SearchQuery query, SearchScope scope, SearchOptions options = null); + /// /// Cancels the search matching the specified , if it is in progress. /// diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index 12c75fb1..54d8bac9 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -69,6 +69,68 @@ namespace slskd.Search private IOptionsMonitor OptionsMonitor { get; } private IHubContext SearchHub { get; set; } + /// + /// Deletes the specified ssearch. + /// + /// The search to delete. + /// The operation context. + public Task DeleteAsync(Search search) + { + if (search == default) + { + throw new ArgumentNullException(nameof(search)); + } + + return DoDeleteAsync(search); + + async Task DoDeleteAsync(Search search) + { + using var context = ContextFactory.CreateDbContext(); + context.Searches.Remove(search); + await context.SaveChangesAsync(); + + await SearchHub.BroadcastDeleteAsync(search); + } + } + + /// + /// Finds a single search matching the specified . + /// + /// The expression to use to match searches. + /// A value indicating whether to include search responses in the result. + /// The found search, or default if not found. + /// Thrown when an expression is not supplied. + public Task FindAsync(Expression> expression, bool includeResponses = false) + { + if (expression == default) + { + throw new ArgumentException("An expression must be supplied.", nameof(expression)); + } + + using var context = ContextFactory.CreateDbContext(); + + var selector = context.Searches.Where(expression); + + if (!includeResponses) + { + selector = selector.WithoutResponses(); + } + + return selector.FirstOrDefaultAsync(); + } + + /// + /// Returns a list of all completed and in-progress searches, with responses omitted, matching the optional . + /// + /// An optional expression used to match searches. + /// The list of searches matching the specified expression, or all searches if no expression is specified. + public Task> ListAsync(Expression> expression = null) + { + expression ??= s => true; + using var context = ContextFactory.CreateDbContext(); + return context.Searches.Where(expression).WithoutResponses().ToListAsync(); + } + /// /// Performs a search for the specified and . /// @@ -117,10 +179,9 @@ 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 i/o or performance - // while searches are running should investigate this as a cause + // 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; @@ -173,68 +234,6 @@ namespace slskd.Search return search; } - /// - /// Deletes the specified ssearch. - /// - /// The search to delete. - /// The operation context. - public Task DeleteAsync(Search search) - { - if (search == default) - { - throw new ArgumentNullException(nameof(search)); - } - - return DoDeleteAsync(search); - - async Task DoDeleteAsync(Search search) - { - using var context = ContextFactory.CreateDbContext(); - context.Searches.Remove(search); - await context.SaveChangesAsync(); - - await SearchHub.BroadcastDeleteAsync(search); - } - } - - /// - /// Finds a single search matching the specified . - /// - /// The expression to use to match searches. - /// A value indicating whether to include search responses in the result. - /// The found search, or default if not found. - /// Thrown an expression is not supplied. - public Task FindAsync(Expression> expression, bool includeResponses = false) - { - if (expression == default) - { - throw new ArgumentException("An expression must be supplied.", nameof(expression)); - } - - using var context = ContextFactory.CreateDbContext(); - - var selector = context.Searches.Where(expression); - - if (!includeResponses) - { - selector = selector.WithoutResponses(); - } - - return selector.FirstOrDefaultAsync(); - } - - /// - /// Returns a list of all completed and in-progress searches, with responses omitted. - /// - /// An optional expression used to match searches. - /// The list of searches matching the specified expression. - public Task> ListAsync(Expression> expression = null) - { - expression ??= s => true; - using var context = ContextFactory.CreateDbContext(); - return context.Searches.Where(expression).WithoutResponses().ToListAsync(); - } - /// /// Cancels the search matching the specified , if it is in progress. /// -- cgit v1.2.3