aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-01-18 16:43:52 -0600
committerJP Dillingham <jp@dillingham.me>2026-01-18 16:43:52 -0600
commit14827ae832d04e8df0058bb4a580de2ec84cb2bd (patch)
tree0ca8cc843af8401c5e396a198d1cc4e6b1fe6bca /src/slskd
parentdeef26c4a219b4197ca988515d886643c2ff81e8 (diff)
downloadslskd-14827ae832d04e8df0058bb4a580de2ec84cb2bd.tar.gz
add the ability to pass a limit to share search
Diffstat (limited to 'src/slskd')
-rw-r--r--src/slskd/Shares/IShareRepository.cs3
-rw-r--r--src/slskd/Shares/IShareService.cs3
-rw-r--r--src/slskd/Shares/ShareService.cs3
-rw-r--r--src/slskd/Shares/SqliteShareRepository.cs5
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 <paramref name="query"/>.
/// </summary>
/// <param name="query">The search query.</param>
+ /// <param name="limit">An optional row limit.</param>
/// <returns>The list of matching files.</returns>
- IEnumerable<File> Search(SearchQuery query);
+ IEnumerable<File> Search(SearchQuery query, int? limit = null);
/// <summary>
/// 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 <paramref name="query"/> and returns the matching files.
/// </summary>
/// <param name="query">The query for which to search.</param>
+ /// <param name="limit">An optional row limit.</param>
/// <returns>The matching files.</returns>
- Task<IEnumerable<File>> SearchAsync(SearchQuery query);
+ Task<IEnumerable<File>> SearchAsync(SearchQuery query, int? limit = null);
/// <summary>
/// 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 <paramref name="query"/> and returns the matching files.
/// </summary>
/// <param name="query">The query for which to search.</param>
+ /// <param name="limit">An optional row limit.</param>
/// <returns>The matching files.</returns>
- public Task<IEnumerable<File>> SearchAsync(SearchQuery query)
+ public Task<IEnumerable<File>> 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 <paramref name="query"/>.
/// </summary>
/// <param name="query">The search query.</param>
+ /// <param name="limit">An optional row limit.</param>
/// <returns>The list of matching files.</returns>
- public IEnumerable<Soulseek.File> Search(SearchQuery query)
+ public IEnumerable<Soulseek.File> 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<Soulseek.File>();