diff options
author | default <nobody@localhost> | 2024-05-09 09:31:10 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2024-05-09 09:31:10 +0200 |
commit | cccc5454c259d0d4ca600b3e1165979c352be54f (patch) | |
tree | 1305ccbed7fab0d5112d7e211dc47f951aac76e4 /data.c | |
parent | 8de93b9cd72ef0cde8b5bb620f376e9b926354dd (diff) |
Added a maximum results argument to content_search().
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -2491,9 +2491,12 @@ void notify_clear(snac *snac) /** searches **/ -xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int *timeout) +xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout) /* returns a list of posts which content matches the regex */ { + if (regex == NULL || *regex == '\0') + return xs_list_new(); + xs_set seen; xs_set_init(&seen); @@ -2517,7 +2520,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i xs_list_next(pub_tl, &pub_md5, &pub_c); xs_list_next(priv_tl, &priv_md5, &priv_c); - for (;;) { + while (max_res > 0) { char *md5 = NULL; enum { NONE, PUBLIC, PRIVATE } from = NONE; @@ -2587,8 +2590,10 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i /* apply regex */ xs *l = xs_regex_select_n(c, regex, 1); - if (xs_list_len(l)) + if (xs_list_len(l)) { xs_set_add(&seen, md5); + max_res--; + } } return xs_set_result(&seen); |