diff options
| -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) | |||
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | 335 | ||
| 336 | int 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 | |||
| 336 | d_char *index_list(const char *fn, int max) | 349 | d_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 | ||
| 591 | d_char *_object_metadata(const char *id, const char *idxsfx) | 604 | d_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 | |||
| 612 | int 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 | |||
| 620 | int 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 | ||
| 600 | d_char *object_children(const char *id) | 628 | d_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 | ||
| 607 | d_char *object_likes(const char *id) | 636 | d_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 | ||
| 613 | d_char *object_announces(const char *id) | 643 | d_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 | ||
| @@ -57,6 +57,7 @@ double mtime_nl(const char *fn, int *n_link); | |||
| 57 | int index_add(const char *fn, const char *md5); | 57 | int index_add(const char *fn, const char *md5); |
| 58 | int index_del(const char *fn, const char *md5); | 58 | int index_del(const char *fn, const char *md5); |
| 59 | int index_first(const char *fn, char *buf, int size); | 59 | int index_first(const char *fn, char *buf, int size); |
| 60 | int index_len(const char *fn); | ||
| 60 | d_char *index_list(const char *fn, int max); | 61 | d_char *index_list(const char *fn, int max); |
| 61 | d_char *index_list_desc(const char *fn, int skip, int show); | 62 | d_char *index_list_desc(const char *fn, int skip, int show); |
| 62 | 63 | ||
| @@ -70,6 +71,9 @@ int object_del(const char *id); | |||
| 70 | int object_del_if_unref(const char *id); | 71 | int object_del_if_unref(const char *id); |
| 71 | int object_admire(const char *id, const char *actor, int like); | 72 | int object_admire(const char *id, const char *actor, int like); |
| 72 | 73 | ||
| 74 | int object_likes_len(const char *id); | ||
| 75 | int object_announces_len(const char *id); | ||
| 76 | |||
| 73 | d_char *object_children(const char *id); | 77 | d_char *object_children(const char *id); |
| 74 | d_char *object_likes(const char *id); | 78 | d_char *object_likes(const char *id); |
| 75 | d_char *object_announces(const char *id); | 79 | d_char *object_announces(const char *id); |