commit 321f64e

green  ·  2025-05-19 13:25:11 +0000 UTC
parent 00fd1a1
performance: use following_list_len in more places
3 files changed,  +11, -13
M data.c
+2, -4
 1@@ -3204,8 +3204,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
 2         int total = 0;
 3 
 4         if (show_contact_metrics) {
 5-            xs *l = follower_list(&snac);
 6-            total = xs_list_len(l);
 7+            total = follower_list_len(&snac);
 8         }
 9 
10         xs *id = xs_fmt("%s/%s", snac.actor, p_path);
11@@ -3216,8 +3215,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
12         int total = 0;
13 
14         if (show_contact_metrics) {
15-            xs *l = following_list(&snac);
16-            total = xs_list_len(l);
17+            total = following_list_len(&snac);
18         }
19 
20         xs *id = xs_fmt("%s/%s", snac.actor, p_path);
M data.c
+1, -1
1@@ -1216,7 +1216,7 @@ int follower_check(snac *snac, const char *actor)
2 
3 
4 int follower_list_len(snac *snac)
5-/* returns the number followers */
6+/* returns the number of followers */
7 {
8     xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0);
9     return xs_list_len(list);
+8, -8
 1@@ -680,10 +680,10 @@ xs_dict *mastoapi_account(snac *logged, const xs_dict *actor)
 2 
 3             /* does this user want to publish their contact metrics? */
 4             if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) {
 5-                xs *fwing = following_list(&user);
 6-                xs *fwers = follower_list(&user);
 7-                xs *ni = xs_number_new(xs_list_len(fwing));
 8-                xs *ne = xs_number_new(xs_list_len(fwers));
 9+                int fwing = following_list_len(&user);
10+                int fwers = follower_list_len(&user);
11+                xs *ni = xs_number_new(fwing);
12+                xs *ne = xs_number_new(fwers);
13 
14                 acct = xs_dict_append(acct, "followers_count", ne);
15                 acct = xs_dict_append(acct, "following_count", ni);
16@@ -1309,10 +1309,10 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
17 
18     /* does this user want to publish their contact metrics? */
19     if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) {
20-        xs *fwing = following_list(&snac);
21-        xs *fwers = follower_list(&snac);
22-        xs *ni = xs_number_new(xs_list_len(fwing));
23-        xs *ne = xs_number_new(xs_list_len(fwers));
24+        int fwing = following_list_len(&snac);
25+        int fwers = follower_list_len(&snac);
26+        xs *ni = xs_number_new(fwing);
27+        xs *ne = xs_number_new(fwers);
28 
29         acct = xs_dict_append(acct, "followers_count", ne);
30         acct = xs_dict_append(acct, "following_count", ni);