summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2022-12-02 19:14:59 +0100
committerGravatar default2022-12-02 19:14:59 +0100
commitc00e3afcdc8cf1503439a174621090b133ad329f (patch)
tree3738fb8d555a55878011cc70a33a05733e2322e8 /data.c
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-c00e3afcdc8cf1503439a174621090b133ad329f.tar.gz
snac2-c00e3afcdc8cf1503439a174621090b133ad329f.tar.xz
snac2-c00e3afcdc8cf1503439a174621090b133ad329f.zip
Big data storage change.
Diffstat (limited to 'data.c')
-rw-r--r--data.c77
1 files changed, 43 insertions, 34 deletions
diff --git a/data.c b/data.c
index 51ee2c7..e9f3d93 100644
--- a/data.c
+++ b/data.c
@@ -116,6 +116,7 @@ void user_free(snac *snac)
116 xs_free(snac->config); 116 xs_free(snac->config);
117 xs_free(snac->key); 117 xs_free(snac->key);
118 xs_free(snac->actor); 118 xs_free(snac->actor);
119 xs_free(snac->md5);
119} 120}
120 121
121 122
@@ -154,6 +155,7 @@ int user_open(snac *snac, char *uid)
154 155
155 if ((snac->key = xs_json_loads(key_data)) != NULL) { 156 if ((snac->key = xs_json_loads(key_data)) != NULL) {
156 snac->actor = xs_fmt("%s/%s", srv_baseurl, uid); 157 snac->actor = xs_fmt("%s/%s", srv_baseurl, uid);
158 snac->md5 = xs_md5_hex(snac->actor, strlen(snac->actor));
157 ret = 1; 159 ret = 1;
158 } 160 }
159 else 161 else
@@ -566,14 +568,31 @@ int object_del_if_unref(const char *id)
566} 568}
567 569
568 570
571d_char *_object_metadata(const char *id, const char *idxsfx)
572/* returns the content of a metadata index */
573{
574 xs *fn = _object_fn(id);
575 fn = xs_replace_i(fn, ".json", idxsfx);
576 return index_list(fn, XS_ALL);
577}
578
579
569d_char *object_children(const char *id) 580d_char *object_children(const char *id)
570/* returns the list of an object's children */ 581/* returns the list of an object's children */
571{ 582{
572 xs *fn = _object_fn(id); 583 return _object_metadata(id, "_c.idx");
584}
573 585
574 fn = xs_replace_i(fn, ".json", "_c.idx");
575 586
576 return index_list(fn, XS_ALL); 587d_char *object_likes(const char *id)
588{
589 return _object_metadata(id, "_l.idx");
590}
591
592
593d_char *object_announces(const char *id)
594{
595 return _object_metadata(id, "_a.idx");
577} 596}
578 597
579 598
@@ -818,35 +837,6 @@ d_char *timeline_get(snac *snac, char *fn)
818} 837}
819 838
820 839
821d_char *_timeline_list(snac *snac, char *directory, int max)
822/* returns a list of the timeline filenames */
823{
824 xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, directory);
825 int c_max;
826
827 /* maximum number of items in the timeline */
828 c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
829
830 /* never more timeline entries than the configured maximum */
831 if (max > c_max)
832 max = c_max;
833
834 return xs_glob_n(spec, 0, 1, max);
835}
836
837
838d_char *timeline_list(snac *snac, int max)
839{
840 return _timeline_list(snac, "timeline", max);
841}
842
843
844d_char *local_list(snac *snac, int max)
845{
846 return _timeline_list(snac, "local", max);
847}
848
849
850d_char *_timeline_new_fn(snac *snac, char *id) 840d_char *_timeline_new_fn(snac *snac, char *id)
851/* creates a new filename */ 841/* creates a new filename */
852{ 842{
@@ -1050,7 +1040,7 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer
1050} 1040}
1051 1041
1052 1042
1053d_char *timeline_top_level(snac *snac, d_char *list) 1043d_char *timeline_top_level(d_char *list)
1054/* returns the top level md5 entries from this index */ 1044/* returns the top level md5 entries from this index */
1055{ 1045{
1056 d_char *tl = xs_list_new(); 1046 d_char *tl = xs_list_new();
@@ -1094,7 +1084,26 @@ d_char *timeline_top_level(snac *snac, d_char *list)
1094} 1084}
1095 1085
1096 1086
1097void timeline_admire(snac *snac, char *id, char *admirer, int like) 1087d_char *timeline_list(snac *snac, const char *idx_name, int max)
1088/* returns a timeline */
1089{
1090 int c_max;
1091
1092 /* maximum number of items in the timeline */
1093 c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
1094
1095 /* never more timeline entries than the configured maximum */
1096 if (max > c_max)
1097 max = c_max;
1098
1099 xs *idx = xs_fmt("%s/%s.idx", snac->basedir, idx_name);
1100 xs *list = index_list_desc(idx, max);
1101
1102 return timeline_top_level(list);
1103}
1104
1105
1106void timeline_admire(snac *snac, char *o_msg, char *id, char *admirer, int like)
1098/* updates a timeline entry with a new admiration */ 1107/* updates a timeline entry with a new admiration */
1099{ 1108{
1100 xs *ofn = _timeline_find_fn(snac, id); 1109 xs *ofn = _timeline_find_fn(snac, id);