From 38f3f82a77ed4782a9c4e1b4e5a6d9d4c71390a2 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 11 Jul 2023 13:11:50 +0200 Subject: Limit amount of search results When a user enters a search term that is too generic, slcl would generate a long list of search results, where this generation could have a big impact on the server performance and its available resources. Therefore, it is reasonable to limit the number of search results to an arbitrary limit, so that users are forced to enter a more specific search term in order to achieve more relevant results. --- main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 19178f4..762db88 100644 --- a/main.c +++ b/main.c @@ -621,6 +621,7 @@ struct search_args static int search_fn(const char *const fpath, const struct stat *const sb, bool *const done, void *const user) { + static const size_t limit = 200; const struct search_args *const sa = user; const char *rel = fpath + strlen(sa->root); struct page_search *const res = sa->s; @@ -650,7 +651,13 @@ static int search_fn(const char *const fpath, const struct stat *const sb, } res->results = results; - res->n++; + + if (++res->n >= limit) + { + sa->s->limit_exceeded = true; + *done = true; + } + return 0; failure: -- cgit v1.2.3