Răsfoiți Sursa

performance: use following_list_len in more places

green 1 an în urmă
părinte
comite
321f64ed70
3 a modificat fișierele cu 11 adăugiri și 13 ștergeri
  1. 2 4
      activitypub.c
  2. 1 1
      data.c
  3. 8 8
      mastoapi.c

+ 2 - 4
activitypub.c

@@ -3204,8 +3204,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
         int total = 0;
 
         if (show_contact_metrics) {
-            xs *l = follower_list(&snac);
-            total = xs_list_len(l);
+            total = follower_list_len(&snac);
         }
 
         xs *id = xs_fmt("%s/%s", snac.actor, p_path);
@@ -3216,8 +3215,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
         int total = 0;
 
         if (show_contact_metrics) {
-            xs *l = following_list(&snac);
-            total = xs_list_len(l);
+            total = following_list_len(&snac);
         }
 
         xs *id = xs_fmt("%s/%s", snac.actor, p_path);

+ 1 - 1
data.c

@@ -1216,7 +1216,7 @@ int follower_check(snac *snac, const char *actor)
 
 
 int follower_list_len(snac *snac)
-/* returns the number followers */
+/* returns the number of followers */
 {
     xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0);
     return xs_list_len(list);

+ 8 - 8
mastoapi.c

@@ -680,10 +680,10 @@ xs_dict *mastoapi_account(snac *logged, const xs_dict *actor)
 
             /* does this user want to publish their contact metrics? */
             if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) {
-                xs *fwing = following_list(&user);
-                xs *fwers = follower_list(&user);
-                xs *ni = xs_number_new(xs_list_len(fwing));
-                xs *ne = xs_number_new(xs_list_len(fwers));
+                int fwing = following_list_len(&user);
+                int fwers = follower_list_len(&user);
+                xs *ni = xs_number_new(fwing);
+                xs *ne = xs_number_new(fwers);
 
                 acct = xs_dict_append(acct, "followers_count", ne);
                 acct = xs_dict_append(acct, "following_count", ni);
@@ -1309,10 +1309,10 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
 
     /* does this user want to publish their contact metrics? */
     if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) {
-        xs *fwing = following_list(&snac);
-        xs *fwers = follower_list(&snac);
-        xs *ni = xs_number_new(xs_list_len(fwing));
-        xs *ne = xs_number_new(xs_list_len(fwers));
+        int fwing = following_list_len(&snac);
+        int fwers = follower_list_len(&snac);
+        xs *ni = xs_number_new(fwing);
+        xs *ne = xs_number_new(fwers);
 
         acct = xs_dict_append(acct, "followers_count", ne);
         acct = xs_dict_append(acct, "following_count", ni);