diff options
| author | 2022-11-25 17:48:43 +0100 | |
|---|---|---|
| committer | 2022-11-25 17:48:43 +0100 | |
| commit | c0e31935291ea14b6b9ad059bc6169f92f9c7e31 (patch) | |
| tree | 106cfe0e7c3192a0d25e56cd5c20f40e20f80aa6 | |
| parent | Also purge the public/ and private/ caches. (diff) | |
| download | snac2-c0e31935291ea14b6b9ad059bc6169f92f9c7e31.tar.gz snac2-c0e31935291ea14b6b9ad059bc6169f92f9c7e31.tar.xz snac2-c0e31935291ea14b6b9ad059bc6169f92f9c7e31.zip | |
New function object_user_cache().
| -rw-r--r-- | data.c | 28 |
1 files changed, 19 insertions, 9 deletions
| @@ -206,6 +206,8 @@ double mtime_nl(const char *fn, int *n_link) | |||
| 206 | 206 | ||
| 207 | /** database 2.1+ **/ | 207 | /** database 2.1+ **/ |
| 208 | 208 | ||
| 209 | /** indexes **/ | ||
| 210 | |||
| 209 | int index_add_md5(const char *fn, const char *md5) | 211 | int index_add_md5(const char *fn, const char *md5) |
| 210 | /* adds an md5 to an index */ | 212 | /* adds an md5 to an index */ |
| 211 | { | 213 | { |
| @@ -363,6 +365,8 @@ d_char *index_list_desc(const char *fn, int max) | |||
| 363 | } | 365 | } |
| 364 | 366 | ||
| 365 | 367 | ||
| 368 | /** objects **/ | ||
| 369 | |||
| 366 | d_char *_object_fn_by_md5(const char *md5) | 370 | d_char *_object_fn_by_md5(const char *md5) |
| 367 | { | 371 | { |
| 368 | xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]); | 372 | xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]); |
| @@ -526,6 +530,19 @@ int object_admire(const char *id, const char *actor, int like) | |||
| 526 | } | 530 | } |
| 527 | 531 | ||
| 528 | 532 | ||
| 533 | int object_user_cache(snac *snac, const char *id, const char *cachedir) | ||
| 534 | /* caches an object into a user cache */ | ||
| 535 | { | ||
| 536 | xs *ofn = _object_fn(id); | ||
| 537 | xs *l = xs_split(ofn, "/"); | ||
| 538 | xs *cfn = xs_fmt("%s/%s/%s", snac->basedir, cachedir, xs_list_get(l, -1)); | ||
| 539 | |||
| 540 | return link(ofn, cfn); | ||
| 541 | } | ||
| 542 | |||
| 543 | |||
| 544 | /** specialized functions **/ | ||
| 545 | |||
| 529 | d_char *_follower_fn(snac *snac, char *actor) | 546 | d_char *_follower_fn(snac *snac, char *actor) |
| 530 | { | 547 | { |
| 531 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | 548 | xs *md5 = xs_md5_hex(actor, strlen(actor)); |
| @@ -905,21 +922,14 @@ void timeline_object_add(snac *snac, const char *id, char *msg) | |||
| 905 | xs *idx = xs_fmt("%s/private.idx", snac->basedir); | 922 | xs *idx = xs_fmt("%s/private.idx", snac->basedir); |
| 906 | index_add(idx, id); | 923 | index_add(idx, id); |
| 907 | 924 | ||
| 908 | /* build the name for the linked copy in the private cache */ | 925 | object_user_cache(snac, id, "private"); |
| 909 | xs *ofn = _object_fn(id); | ||
| 910 | xs *l = xs_split(ofn, "/"); | ||
| 911 | xs *cfn = xs_fmt("%s/private/%s", snac->basedir, xs_list_get(l, -1)); | ||
| 912 | |||
| 913 | link(ofn, cfn); | ||
| 914 | 926 | ||
| 915 | if (xs_startswith(id, snac->actor)) { | 927 | if (xs_startswith(id, snac->actor)) { |
| 916 | /* add to the public index */ | 928 | /* add to the public index */ |
| 917 | idx = xs_replace_i(idx, "private", "public"); | 929 | idx = xs_replace_i(idx, "private", "public"); |
| 918 | index_add(idx, id); | 930 | index_add(idx, id); |
| 919 | 931 | ||
| 920 | /* add to the public cache */ | 932 | object_user_cache(snac, id, "public"); |
| 921 | cfn = xs_replace_i(cfn, "private", "public"); | ||
| 922 | link(ofn, cfn); | ||
| 923 | } | 933 | } |
| 924 | } | 934 | } |
| 925 | 935 | ||