diff options
author | default <nobody@localhost> | 2022-12-10 11:19:26 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2022-12-10 11:19:26 +0100 |
commit | 83a68d635da380329ed5cdd312011701beef6f44 (patch) | |
tree | 32ef968548a73682c3444348d50c6b337b6a2008 | |
parent | 6fd5d14428e6a6145cda2ee1a25118696da4e4eb (diff) |
New function index_len().
-rw-r--r-- | data.c | 47 | ||||
-rw-r--r-- | snac.h | 4 |
2 files changed, 43 insertions, 8 deletions
@@ -333,6 +333,19 @@ int index_first(const char *fn, char *line, int size) } +int index_len(const char *fn) +/* returns the number of elements in an index */ +{ + struct stat st; + int len = 0; + + if (stat(fn, &st) != -1) + len = st.st_size / 33; + + return len; +} + + d_char *index_list(const char *fn, int max) /* returns an index as a list */ { @@ -588,31 +601,49 @@ int object_del_if_unref(const char *id) } -d_char *_object_metadata(const char *id, const char *idxsfx) -/* returns the content of a metadata index */ +d_char *_object_index_fn(const char *id, const char *idxsfx) +/* returns the filename of an object's index */ { - xs *fn = _object_fn(id); - fn = xs_replace_i(fn, ".json", idxsfx); - return index_list(fn, XS_ALL); + d_char *fn = _object_fn(id); + return xs_replace_i(fn, ".json", idxsfx); +} + + +int object_likes_len(const char *id) +/* returns the number of likes (without reading the index) */ +{ + xs *fn = _object_index_fn(id, "_l.idx"); + return index_len(fn); +} + + +int object_announces_len(const char *id) +/* returns the number of announces (without reading the index) */ +{ + xs *fn = _object_index_fn(id, "_a.idx"); + return index_len(fn); } d_char *object_children(const char *id) /* returns the list of an object's children */ { - return _object_metadata(id, "_c.idx"); + xs *fn = _object_index_fn(id, "_c.idx"); + return index_list(fn, XS_ALL); } d_char *object_likes(const char *id) { - return _object_metadata(id, "_l.idx"); + xs *fn = _object_index_fn(id, "_l.idx"); + return index_list(fn, XS_ALL); } d_char *object_announces(const char *id) { - return _object_metadata(id, "_a.idx"); + xs *fn = _object_index_fn(id, "_a.idx"); + return index_list(fn, XS_ALL); } @@ -57,6 +57,7 @@ double mtime_nl(const char *fn, int *n_link); int index_add(const char *fn, const char *md5); int index_del(const char *fn, const char *md5); int index_first(const char *fn, char *buf, int size); +int index_len(const char *fn); d_char *index_list(const char *fn, int max); d_char *index_list_desc(const char *fn, int skip, int show); @@ -70,6 +71,9 @@ int object_del(const char *id); int object_del_if_unref(const char *id); int object_admire(const char *id, const char *actor, int like); +int object_likes_len(const char *id); +int object_announces_len(const char *id); + d_char *object_children(const char *id); d_char *object_likes(const char *id); d_char *object_announces(const char *id); |