diff options
| author | 2022-12-10 11:19:26 +0100 | |
|---|---|---|
| committer | 2022-12-10 11:19:26 +0100 | |
| commit | 83a68d635da380329ed5cdd312011701beef6f44 (patch) | |
| tree | 32ef968548a73682c3444348d50c6b337b6a2008 /data.c | |
| parent | In process_queue(), do not retry for 404 or 410 status. (diff) | |
| download | snac2-83a68d635da380329ed5cdd312011701beef6f44.tar.gz snac2-83a68d635da380329ed5cdd312011701beef6f44.tar.xz snac2-83a68d635da380329ed5cdd312011701beef6f44.zip | |
New function index_len().
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 47 |
1 files changed, 39 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 | ||