commit 00fd1a1
green
·
2025-03-29 00:27:46 +0000 UTC
parent 072ae21
performance: functions to get the number of followers
M
data.c
+17,
-0
1@@ -1215,6 +1215,14 @@ int follower_check(snac *snac, const char *actor)
2 }
3
4
5+int follower_list_len(snac *snac)
6+/* returns the number followers */
7+{
8+ xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0);
9+ return xs_list_len(list);
10+}
11+
12+
13 xs_list *follower_list(snac *snac)
14 /* returns the list of followers */
15 {
16@@ -1709,6 +1717,15 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
17 }
18
19
20+int following_list_len(snac *snac)
21+/* returns number of people being followed */
22+{
23+ xs *spec = xs_fmt("%s/following/" "*_a.json", snac->basedir);
24+ xs *glist = xs_glob(spec, 0, 0);
25+ return xs_list_len(glist);
26+}
27+
28+
29 xs_list *following_list(snac *snac)
30 /* returns the list of people being followed */
31 {
M
html.c
+2,
-10
1@@ -821,11 +821,7 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url)
2
3 /* show metrics in og:description? */
4 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
5- xs *fwers = follower_list(user);
6- xs *fwing = following_list(user);
7-
8- xs *s1 = xs_fmt(L("%d following, %d followers"),
9- xs_list_len(fwing), xs_list_len(fwers));
10+ xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
11
12 s1 = xs_str_cat(s1, " ยท ");
13
14@@ -1166,11 +1162,7 @@ static xs_html *html_user_body(snac *user, int read_only)
15 }
16
17 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
18- xs *fwers = follower_list(user);
19- xs *fwing = following_list(user);
20-
21- xs *s1 = xs_fmt(L("%d following, %d followers"),
22- xs_list_len(fwing), xs_list_len(fwers));
23+ xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
24
25 xs_html_add(top_user,
26 xs_html_tag("p",
M
snac.h
+2,
-0
1@@ -153,6 +153,7 @@ int follower_add(snac *snac, const char *actor);
2 int follower_del(snac *snac, const char *actor);
3 int follower_check(snac *snac, const char *actor);
4 xs_list *follower_list(snac *snac);
5+int follower_list_len(snac *snac);
6
7 int pending_add(snac *user, const char *actor, const xs_dict *msg);
8 int pending_check(snac *user, const char *actor);
9@@ -184,6 +185,7 @@ int following_del(snac *snac, const char *actor);
10 int following_check(snac *snac, const char *actor);
11 int following_get(snac *snac, const char *actor, xs_dict **data);
12 xs_list *following_list(snac *snac);
13+int following_list_len(snac *snac);
14
15 void mute(snac *snac, const char *actor);
16 void unmute(snac *snac, const char *actor);