diff options
| author | 2025-03-29 01:27:46 +0100 | |
|---|---|---|
| committer | 2025-05-19 15:19:38 +0200 | |
| commit | 00fd1a1c3eb99c9e441276a7ce8697a1582152b7 (patch) | |
| tree | a0431b0db7e73508ea2c02190fd0dbe9af961601 | |
| parent | Operations on the 'people' page redirects back to it instead of 'admin'. (diff) | |
| download | snac2-00fd1a1c3eb99c9e441276a7ce8697a1582152b7.tar.gz snac2-00fd1a1c3eb99c9e441276a7ce8697a1582152b7.tar.xz snac2-00fd1a1c3eb99c9e441276a7ce8697a1582152b7.zip | |
performance: functions to get the number of followers
| -rw-r--r-- | data.c | 17 | ||||
| -rw-r--r-- | html.c | 12 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 21 insertions, 10 deletions
| @@ -1215,6 +1215,14 @@ int follower_check(snac *snac, const char *actor) | |||
| 1215 | } | 1215 | } |
| 1216 | 1216 | ||
| 1217 | 1217 | ||
| 1218 | int follower_list_len(snac *snac) | ||
| 1219 | /* returns the number followers */ | ||
| 1220 | { | ||
| 1221 | xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0); | ||
| 1222 | return xs_list_len(list); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | |||
| 1218 | xs_list *follower_list(snac *snac) | 1226 | xs_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 | ||
| 1720 | int 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 | |||
| 1712 | xs_list *following_list(snac *snac) | 1729 | xs_list *following_list(snac *snac) |
| 1713 | /* returns the list of people being followed */ | 1730 | /* returns the list of people being followed */ |
| 1714 | { | 1731 | { |
| @@ -821,11 +821,7 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url) | |||
| 821 | 821 | ||
| 822 | /* show metrics in og:description? */ | 822 | /* show metrics in og:description? */ |
| 823 | if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { | 823 | if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { |
| 824 | xs *fwers = follower_list(user); | 824 | xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user)); |
| 825 | xs *fwing = following_list(user); | ||
| 826 | |||
| 827 | xs *s1 = xs_fmt(L("%d following, %d followers"), | ||
| 828 | xs_list_len(fwing), xs_list_len(fwers)); | ||
| 829 | 825 | ||
| 830 | s1 = xs_str_cat(s1, " · "); | 826 | s1 = xs_str_cat(s1, " · "); |
| 831 | 827 | ||
| @@ -1166,11 +1162,7 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 1166 | } | 1162 | } |
| 1167 | 1163 | ||
| 1168 | if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { | 1164 | if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { |
| 1169 | xs *fwers = follower_list(user); | 1165 | xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user)); |
| 1170 | xs *fwing = following_list(user); | ||
| 1171 | |||
| 1172 | xs *s1 = xs_fmt(L("%d following, %d followers"), | ||
| 1173 | xs_list_len(fwing), xs_list_len(fwers)); | ||
| 1174 | 1166 | ||
| 1175 | xs_html_add(top_user, | 1167 | xs_html_add(top_user, |
| 1176 | xs_html_tag("p", | 1168 | xs_html_tag("p", |
| @@ -153,6 +153,7 @@ int follower_add(snac *snac, const char *actor); | |||
| 153 | int follower_del(snac *snac, const char *actor); | 153 | int follower_del(snac *snac, const char *actor); |
| 154 | int follower_check(snac *snac, const char *actor); | 154 | int follower_check(snac *snac, const char *actor); |
| 155 | xs_list *follower_list(snac *snac); | 155 | xs_list *follower_list(snac *snac); |
| 156 | int follower_list_len(snac *snac); | ||
| 156 | 157 | ||
| 157 | int pending_add(snac *user, const char *actor, const xs_dict *msg); | 158 | int pending_add(snac *user, const char *actor, const xs_dict *msg); |
| 158 | int pending_check(snac *user, const char *actor); | 159 | int pending_check(snac *user, const char *actor); |
| @@ -184,6 +185,7 @@ int following_del(snac *snac, const char *actor); | |||
| 184 | int following_check(snac *snac, const char *actor); | 185 | int following_check(snac *snac, const char *actor); |
| 185 | int following_get(snac *snac, const char *actor, xs_dict **data); | 186 | int following_get(snac *snac, const char *actor, xs_dict **data); |
| 186 | xs_list *following_list(snac *snac); | 187 | xs_list *following_list(snac *snac); |
| 188 | int following_list_len(snac *snac); | ||
| 187 | 189 | ||
| 188 | void mute(snac *snac, const char *actor); | 190 | void mute(snac *snac, const char *actor); |
| 189 | void unmute(snac *snac, const char *actor); | 191 | void unmute(snac *snac, const char *actor); |