summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2025-05-20 06:32:39 +0200
committerGravatar grunfink2025-05-20 06:32:39 +0200
commitaa49cf4222e24535b577649add66be8f90cca17f (patch)
tree96e63bc2a4e2a4e1869c5b84bbafe7d434d2f435
parentImproved post language markup. (diff)
parentperformance: use following_list_len in more places (diff)
downloadsnac2-aa49cf4222e24535b577649add66be8f90cca17f.tar.gz
snac2-aa49cf4222e24535b577649add66be8f90cca17f.tar.xz
snac2-aa49cf4222e24535b577649add66be8f90cca17f.zip
Merge pull request 'Faster performance metrics' (#395) from dandelions/snac2:pr-faster-metric into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/395
-rw-r--r--activitypub.c6
-rw-r--r--data.c17
-rw-r--r--html.c12
-rw-r--r--mastoapi.c16
-rw-r--r--snac.h2
5 files changed, 31 insertions, 22 deletions
diff --git a/activitypub.c b/activitypub.c
index a7e133a..120b4a1 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -3204,8 +3204,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
3204 int total = 0; 3204 int total = 0;
3205 3205
3206 if (show_contact_metrics) { 3206 if (show_contact_metrics) {
3207 xs *l = follower_list(&snac); 3207 total = follower_list_len(&snac);
3208 total = xs_list_len(l);
3209 } 3208 }
3210 3209
3211 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 3210 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,
3216 int total = 0; 3215 int total = 0;
3217 3216
3218 if (show_contact_metrics) { 3217 if (show_contact_metrics) {
3219 xs *l = following_list(&snac); 3218 total = following_list_len(&snac);
3220 total = xs_list_len(l);
3221 } 3219 }
3222 3220
3223 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 3221 xs *id = xs_fmt("%s/%s", snac.actor, p_path);
diff --git a/data.c b/data.c
index e3fa52d..f9d27f9 100644
--- a/data.c
+++ b/data.c
@@ -1215,6 +1215,14 @@ int follower_check(snac *snac, const char *actor)
1215} 1215}
1216 1216
1217 1217
1218int follower_list_len(snac *snac)
1219/* returns the number of followers */
1220{
1221 xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0);
1222 return xs_list_len(list);
1223}
1224
1225
1218xs_list *follower_list(snac *snac) 1226xs_list *follower_list(snac *snac)
1219/* returns the list of followers */ 1227/* returns the list of followers */
1220{ 1228{
@@ -1709,6 +1717,15 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
1709} 1717}
1710 1718
1711 1719
1720int following_list_len(snac *snac)
1721/* returns number of people being followed */
1722{
1723 xs *spec = xs_fmt("%s/following/" "*_a.json", snac->basedir);
1724 xs *glist = xs_glob(spec, 0, 0);
1725 return xs_list_len(glist);
1726}
1727
1728
1712xs_list *following_list(snac *snac) 1729xs_list *following_list(snac *snac)
1713/* returns the list of people being followed */ 1730/* returns the list of people being followed */
1714{ 1731{
diff --git a/html.c b/html.c
index 5293dfe..de2fdce 100644
--- a/html.c
+++ b/html.c
@@ -811,11 +811,7 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url)
811 811
812 /* show metrics in og:description? */ 812 /* show metrics in og:description? */
813 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { 813 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
814 xs *fwers = follower_list(user); 814 xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
815 xs *fwing = following_list(user);
816
817 xs *s1 = xs_fmt(L("%d following, %d followers"),
818 xs_list_len(fwing), xs_list_len(fwers));
819 815
820 s1 = xs_str_cat(s1, " · "); 816 s1 = xs_str_cat(s1, " · ");
821 817
@@ -1156,11 +1152,7 @@ static xs_html *html_user_body(snac *user, int read_only)
1156 } 1152 }
1157 1153
1158 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { 1154 if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) {
1159 xs *fwers = follower_list(user); 1155 xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user));
1160 xs *fwing = following_list(user);
1161
1162 xs *s1 = xs_fmt(L("%d following, %d followers"),
1163 xs_list_len(fwing), xs_list_len(fwers));
1164 1156
1165 xs_html_add(top_user, 1157 xs_html_add(top_user,
1166 xs_html_tag("p", 1158 xs_html_tag("p",
diff --git a/mastoapi.c b/mastoapi.c
index 7fa0078..a7d9c34 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -680,10 +680,10 @@ xs_dict *mastoapi_account(snac *logged, const xs_dict *actor)
680 680
681 /* does this user want to publish their contact metrics? */ 681 /* does this user want to publish their contact metrics? */
682 if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) { 682 if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) {
683 xs *fwing = following_list(&user); 683 int fwing = following_list_len(&user);
684 xs *fwers = follower_list(&user); 684 int fwers = follower_list_len(&user);
685 xs *ni = xs_number_new(xs_list_len(fwing)); 685 xs *ni = xs_number_new(fwing);
686 xs *ne = xs_number_new(xs_list_len(fwers)); 686 xs *ne = xs_number_new(fwers);
687 687
688 acct = xs_dict_append(acct, "followers_count", ne); 688 acct = xs_dict_append(acct, "followers_count", ne);
689 acct = xs_dict_append(acct, "following_count", ni); 689 acct = xs_dict_append(acct, "following_count", ni);
@@ -1309,10 +1309,10 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
1309 1309
1310 /* does this user want to publish their contact metrics? */ 1310 /* does this user want to publish their contact metrics? */
1311 if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) { 1311 if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) {
1312 xs *fwing = following_list(&snac); 1312 int fwing = following_list_len(&snac);
1313 xs *fwers = follower_list(&snac); 1313 int fwers = follower_list_len(&snac);
1314 xs *ni = xs_number_new(xs_list_len(fwing)); 1314 xs *ni = xs_number_new(fwing);
1315 xs *ne = xs_number_new(xs_list_len(fwers)); 1315 xs *ne = xs_number_new(fwers);
1316 1316
1317 acct = xs_dict_append(acct, "followers_count", ne); 1317 acct = xs_dict_append(acct, "followers_count", ne);
1318 acct = xs_dict_append(acct, "following_count", ni); 1318 acct = xs_dict_append(acct, "following_count", ni);
diff --git a/snac.h b/snac.h
index 2ab9a67..256731f 100644
--- a/snac.h
+++ b/snac.h
@@ -153,6 +153,7 @@ int follower_add(snac *snac, const char *actor);
153int follower_del(snac *snac, const char *actor); 153int follower_del(snac *snac, const char *actor);
154int follower_check(snac *snac, const char *actor); 154int follower_check(snac *snac, const char *actor);
155xs_list *follower_list(snac *snac); 155xs_list *follower_list(snac *snac);
156int follower_list_len(snac *snac);
156 157
157int pending_add(snac *user, const char *actor, const xs_dict *msg); 158int pending_add(snac *user, const char *actor, const xs_dict *msg);
158int pending_check(snac *user, const char *actor); 159int pending_check(snac *user, const char *actor);
@@ -184,6 +185,7 @@ int following_del(snac *snac, const char *actor);
184int following_check(snac *snac, const char *actor); 185int following_check(snac *snac, const char *actor);
185int following_get(snac *snac, const char *actor, xs_dict **data); 186int following_get(snac *snac, const char *actor, xs_dict **data);
186xs_list *following_list(snac *snac); 187xs_list *following_list(snac *snac);
188int following_list_len(snac *snac);
187 189
188void mute(snac *snac, const char *actor); 190void mute(snac *snac, const char *actor);
189void unmute(snac *snac, const char *actor); 191void unmute(snac *snac, const char *actor);