summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-25 17:48:43 +0100
committerdefault <nobody@localhost>2022-11-25 17:48:43 +0100
commitc0e31935291ea14b6b9ad059bc6169f92f9c7e31 (patch)
tree106cfe0e7c3192a0d25e56cd5c20f40e20f80aa6 /data.c
parente93a79e06d12d5fa3a4bcac313a01044f0da7a25 (diff)
New function object_user_cache().
Diffstat (limited to 'data.c')
-rw-r--r--data.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/data.c b/data.c
index 5dd9ec9..2a89ee3 100644
--- a/data.c
+++ b/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");
}
}