Quellcode durchsuchen

performance: functions to get the number of followers

green vor 1 Jahr
Ursprung
Commit
00fd1a1c3e
3 geänderte Dateien mit 21 neuen und 10 gelöschten Zeilen
  1. 17 0
      data.c
  2. 2 10
      html.c
  3. 2 0
      snac.h

+ 17 - 0
data.c

@@ -1215,6 +1215,14 @@ int follower_check(snac *snac, const char *actor)
 }
 
 
+int follower_list_len(snac *snac)
+/* returns the number followers */
+{
+    xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0);
+    return xs_list_len(list);
+}
+
+
 xs_list *follower_list(snac *snac)
 /* returns the list of followers */
 {
@@ -1709,6 +1717,15 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
 }
 
 
+int following_list_len(snac *snac)
+/* returns number of people being followed */
+{
+    xs *spec = xs_fmt("%s/following/" "*_a.json", snac->basedir);
+    xs *glist = xs_glob(spec, 0, 0);
+    return xs_list_len(glist);
+}
+
+
 xs_list *following_list(snac *snac)
 /* returns the list of people being followed */
 {

+ 2 - 10
html.c

@@ -821,11 +821,7 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url)
 
     /* show metrics in og:description? */
     if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
-        xs *fwers = follower_list(user);
-        xs *fwing = following_list(user);
-
-        xs *s1 = xs_fmt(L("%d following, %d followers"),
-            xs_list_len(fwing), xs_list_len(fwers));
+        xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
 
         s1 = xs_str_cat(s1, " · ");
 
@@ -1166,11 +1162,7 @@ static xs_html *html_user_body(snac *user, int read_only)
         }
 
         if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
-            xs *fwers = follower_list(user);
-            xs *fwing = following_list(user);
-
-            xs *s1 = xs_fmt(L("%d following, %d followers"),
-                xs_list_len(fwing), xs_list_len(fwers));
+            xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
 
             xs_html_add(top_user,
                 xs_html_tag("p",

+ 2 - 0
snac.h

@@ -153,6 +153,7 @@ int follower_add(snac *snac, const char *actor);
 int follower_del(snac *snac, const char *actor);
 int follower_check(snac *snac, const char *actor);
 xs_list *follower_list(snac *snac);
+int follower_list_len(snac *snac);
 
 int pending_add(snac *user, const char *actor, const xs_dict *msg);
 int pending_check(snac *user, const char *actor);
@@ -184,6 +185,7 @@ int following_del(snac *snac, const char *actor);
 int following_check(snac *snac, const char *actor);
 int following_get(snac *snac, const char *actor, xs_dict **data);
 xs_list *following_list(snac *snac);
+int following_list_len(snac *snac);
 
 void mute(snac *snac, const char *actor);
 void unmute(snac *snac, const char *actor);