From 14827ae832d04e8df0058bb4a580de2ec84cb2bd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Jan 2026 16:43:52 -0600 Subject: add the ability to pass a limit to share search --- src/slskd/Shares/IShareRepository.cs | 3 ++- src/slskd/Shares/IShareService.cs | 3 ++- src/slskd/Shares/ShareService.cs | 3 ++- src/slskd/Shares/SqliteShareRepository.cs | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/slskd/Shares/IShareRepository.cs b/src/slskd/Shares/IShareRepository.cs index 1ccfeb22..cb6830d6 100644 --- a/src/slskd/Shares/IShareRepository.cs +++ b/src/slskd/Shares/IShareRepository.cs @@ -167,8 +167,9 @@ namespace slskd.Shares /// Searches the database for files matching the specified . /// /// The search query. + /// An optional row limit. /// The list of matching files. - IEnumerable Search(SearchQuery query); + IEnumerable Search(SearchQuery query, int? limit = null); /// /// Attempts to validate the backing database. diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 7db9671b..3b379c98 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -109,8 +109,9 @@ namespace slskd.Shares /// Searches the cache for the specified and returns the matching files. /// /// The query for which to search. + /// An optional row limit. /// The matching files. - Task> SearchAsync(SearchQuery query); + Task> SearchAsync(SearchQuery query, int? limit = null); /// /// Cancels the currently running scan on the local host, if one is running. diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 6068a744..ee63f1bc 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -343,8 +343,9 @@ namespace slskd.Shares /// Searches the cache for the specified and returns the matching files. /// /// The query for which to search. + /// An optional row limit. /// The matching files. - public Task> SearchAsync(SearchQuery query) + public Task> SearchAsync(SearchQuery query, int? limit = null) { var results = AllRepositories.SelectMany(r => r.Search(query)); diff --git a/src/slskd/Shares/SqliteShareRepository.cs b/src/slskd/Shares/SqliteShareRepository.cs index cb0c331a..1d4e6783 100644 --- a/src/slskd/Shares/SqliteShareRepository.cs +++ b/src/slskd/Shares/SqliteShareRepository.cs @@ -517,8 +517,9 @@ namespace slskd.Shares /// Searches the database for files matching the specified . /// /// The search query. + /// An optional row limit. /// The list of matching files. - public IEnumerable Search(SearchQuery query) + public IEnumerable Search(SearchQuery query, int? limit = null) { string Clean(string str) => str.Replace("/", " ") .Replace("\\", " ") @@ -532,7 +533,7 @@ namespace slskd.Shares var sql = $"SELECT files.maskedFilename, files.code, files.size, files.extension, files.attributeJson FROM filenames " + "INNER JOIN files ON filenames.maskedFilename = files.maskedFilename " + $"WHERE filenames MATCH '({match}) {(query.Exclusions.Any() ? $"NOT ({exclusions})" : string.Empty)}' " + - "ORDER BY filenames.maskedFilename ASC;"; + $"ORDER BY filenames.maskedFilename ASC {(limit.HasValue ? $"LIMIT {limit.Value}" : string.Empty)};"; var results = new List(); -- cgit v1.2.3