aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-11 13:11:50 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-11 13:27:49 +0200
commit38f3f82a77ed4782a9c4e1b4e5a6d9d4c71390a2 (patch)
tree4a0d1c0a76f1e38562ad544f0fca5ce80cec32d6 /main.c
parent59e17afe291f9df52d2334b92e88a889c2fe8f6a (diff)
downloadslcl-38f3f82a77ed4782a9c4e1b4e5a6d9d4c71390a2.tar.gz
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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c9
1 files changed, 8 insertions, 1 deletions
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: