summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c47
-rw-r--r--snac.h4
2 files changed, 43 insertions, 8 deletions
diff --git a/data.c b/data.c
index 5c48015..b073840 100644
--- a/data.c
+++ b/data.c
@@ -333,6 +333,19 @@ int index_first(const char *fn, char *line, int size)
333} 333}
334 334
335 335
336int index_len(const char *fn)
337/* returns the number of elements in an index */
338{
339 struct stat st;
340 int len = 0;
341
342 if (stat(fn, &st) != -1)
343 len = st.st_size / 33;
344
345 return len;
346}
347
348
336d_char *index_list(const char *fn, int max) 349d_char *index_list(const char *fn, int max)
337/* returns an index as a list */ 350/* returns an index as a list */
338{ 351{
@@ -588,31 +601,49 @@ int object_del_if_unref(const char *id)
588} 601}
589 602
590 603
591d_char *_object_metadata(const char *id, const char *idxsfx) 604d_char *_object_index_fn(const char *id, const char *idxsfx)
592/* returns the content of a metadata index */ 605/* returns the filename of an object's index */
593{ 606{
594 xs *fn = _object_fn(id); 607 d_char *fn = _object_fn(id);
595 fn = xs_replace_i(fn, ".json", idxsfx); 608 return xs_replace_i(fn, ".json", idxsfx);
596 return index_list(fn, XS_ALL); 609}
610
611
612int object_likes_len(const char *id)
613/* returns the number of likes (without reading the index) */
614{
615 xs *fn = _object_index_fn(id, "_l.idx");
616 return index_len(fn);
617}
618
619
620int object_announces_len(const char *id)
621/* returns the number of announces (without reading the index) */
622{
623 xs *fn = _object_index_fn(id, "_a.idx");
624 return index_len(fn);
597} 625}
598 626
599 627
600d_char *object_children(const char *id) 628d_char *object_children(const char *id)
601/* returns the list of an object's children */ 629/* returns the list of an object's children */
602{ 630{
603 return _object_metadata(id, "_c.idx"); 631 xs *fn = _object_index_fn(id, "_c.idx");
632 return index_list(fn, XS_ALL);
604} 633}
605 634
606 635
607d_char *object_likes(const char *id) 636d_char *object_likes(const char *id)
608{ 637{
609 return _object_metadata(id, "_l.idx"); 638 xs *fn = _object_index_fn(id, "_l.idx");
639 return index_list(fn, XS_ALL);
610} 640}
611 641
612 642
613d_char *object_announces(const char *id) 643d_char *object_announces(const char *id)
614{ 644{
615 return _object_metadata(id, "_a.idx"); 645 xs *fn = _object_index_fn(id, "_a.idx");
646 return index_list(fn, XS_ALL);
616} 647}
617 648
618 649
diff --git a/snac.h b/snac.h
index 39f2f2d..84d4788 100644
--- a/snac.h
+++ b/snac.h
@@ -57,6 +57,7 @@ double mtime_nl(const char *fn, int *n_link);
57int index_add(const char *fn, const char *md5); 57int index_add(const char *fn, const char *md5);
58int index_del(const char *fn, const char *md5); 58int index_del(const char *fn, const char *md5);
59int index_first(const char *fn, char *buf, int size); 59int index_first(const char *fn, char *buf, int size);
60int index_len(const char *fn);
60d_char *index_list(const char *fn, int max); 61d_char *index_list(const char *fn, int max);
61d_char *index_list_desc(const char *fn, int skip, int show); 62d_char *index_list_desc(const char *fn, int skip, int show);
62 63
@@ -70,6 +71,9 @@ int object_del(const char *id);
70int object_del_if_unref(const char *id); 71int object_del_if_unref(const char *id);
71int object_admire(const char *id, const char *actor, int like); 72int object_admire(const char *id, const char *actor, int like);
72 73
74int object_likes_len(const char *id);
75int object_announces_len(const char *id);
76
73d_char *object_children(const char *id); 77d_char *object_children(const char *id);
74d_char *object_likes(const char *id); 78d_char *object_likes(const char *id);
75d_char *object_announces(const char *id); 79d_char *object_announces(const char *id);