mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-26 01:03:37 +00:00
New function object_user_cache().
This commit is contained in:
parent
e93a79e06d
commit
c0e3193529
1 changed files with 19 additions and 9 deletions
28
data.c
28
data.c
|
@ -206,6 +206,8 @@ double mtime_nl(const char *fn, int *n_link)
|
|||
|
||||
/** database 2.1+ **/
|
||||
|
||||
/** indexes **/
|
||||
|
||||
int index_add_md5(const char *fn, const char *md5)
|
||||
/* adds an md5 to an index */
|
||||
{
|
||||
|
@ -363,6 +365,8 @@ d_char *index_list_desc(const char *fn, int max)
|
|||
}
|
||||
|
||||
|
||||
/** objects **/
|
||||
|
||||
d_char *_object_fn_by_md5(const char *md5)
|
||||
{
|
||||
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)
|
|||
}
|
||||
|
||||
|
||||
int object_user_cache(snac *snac, const char *id, const char *cachedir)
|
||||
/* caches an object into a user cache */
|
||||
{
|
||||
xs *ofn = _object_fn(id);
|
||||
xs *l = xs_split(ofn, "/");
|
||||
xs *cfn = xs_fmt("%s/%s/%s", snac->basedir, cachedir, xs_list_get(l, -1));
|
||||
|
||||
return link(ofn, cfn);
|
||||
}
|
||||
|
||||
|
||||
/** specialized functions **/
|
||||
|
||||
d_char *_follower_fn(snac *snac, char *actor)
|
||||
{
|
||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||
|
@ -905,21 +922,14 @@ void timeline_object_add(snac *snac, const char *id, char *msg)
|
|||
xs *idx = xs_fmt("%s/private.idx", snac->basedir);
|
||||
index_add(idx, id);
|
||||
|
||||
/* build the name for the linked copy in the private cache */
|
||||
xs *ofn = _object_fn(id);
|
||||
xs *l = xs_split(ofn, "/");
|
||||
xs *cfn = xs_fmt("%s/private/%s", snac->basedir, xs_list_get(l, -1));
|
||||
|
||||
link(ofn, cfn);
|
||||
object_user_cache(snac, id, "private");
|
||||
|
||||
if (xs_startswith(id, snac->actor)) {
|
||||
/* add to the public index */
|
||||
idx = xs_replace_i(idx, "private", "public");
|
||||
index_add(idx, id);
|
||||
|
||||
/* add to the public cache */
|
||||
cfn = xs_replace_i(cfn, "private", "public");
|
||||
link(ofn, cfn);
|
||||
object_user_cache(snac, id, "public");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue