commit d7c24d1

grunfink  ·  2025-01-15 05:52:27 +0000 UTC
parents 061fa60, 9686ccd
Merge pull request 'Implement limit= on notification fetches' (#276) from nowster/snac2:notification_limits into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/276
1 files changed,  +9, -0
+9, -0
 1@@ -1816,6 +1816,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2             const xs_list *excl = xs_dict_get(args, "exclude_types[]");
 3             const char *min_id = xs_dict_get(args, "min_id");
 4             const char *max_id = xs_dict_get(args, "max_id");
 5+            const char *limit = xs_dict_get(args, "limit");
 6+            int limit_count = 0;
 7+            if (!xs_is_null(limit)) {
 8+                limit_count = atoi(limit);
 9+            }
10 
11             if (dbglevel) {
12                 xs *js = xs_json_dumps(args, 0);
13@@ -1903,6 +1908,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
14                 }
15 
16                 out = xs_list_append(out, mn);
17+                if (!xs_is_null(limit)) {
18+                    if (--limit_count <= 0)
19+                        break;
20+                }
21             }
22 
23             srv_debug(1, xs_fmt("mastoapi_notifications count %d", xs_list_len(out)));