commit aa49cf4
Merge pull request 'Faster performance metrics' (#395) from dandelions/snac2:pr-faster-metric into master Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/395
5 files changed,
+31,
-22
+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
+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 of 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@@ -811,11 +811,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@@ -1156,11 +1152,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",
+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);
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);