commit c0e3193

default  ·  2022-11-25 16:48:43 +0000 UTC
parent e93a79e
New function object_user_cache().
1 files changed,  +19, -9
M data.c
M data.c
+19, -9
 1@@ -206,6 +206,8 @@ double mtime_nl(const char *fn, int *n_link)
 2 
 3 /** database 2.1+ **/
 4 
 5+/** indexes **/
 6+
 7 int index_add_md5(const char *fn, const char *md5)
 8 /* adds an md5 to an index */
 9 {
10@@ -363,6 +365,8 @@ d_char *index_list_desc(const char *fn, int max)
11 }
12 
13 
14+/** objects **/
15+
16 d_char *_object_fn_by_md5(const char *md5)
17 {
18     xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]);
19@@ -526,6 +530,19 @@ int object_admire(const char *id, const char *actor, int like)
20 }
21 
22 
23+int object_user_cache(snac *snac, const char *id, const char *cachedir)
24+/* caches an object into a user cache */
25+{
26+    xs *ofn = _object_fn(id);
27+    xs *l   = xs_split(ofn, "/");
28+    xs *cfn = xs_fmt("%s/%s/%s", snac->basedir, cachedir, xs_list_get(l, -1));
29+
30+    return link(ofn, cfn);
31+}
32+
33+
34+/** specialized functions **/
35+
36 d_char *_follower_fn(snac *snac, char *actor)
37 {
38     xs *md5 = xs_md5_hex(actor, strlen(actor));
39@@ -905,21 +922,14 @@ void timeline_object_add(snac *snac, const char *id, char *msg)
40     xs *idx = xs_fmt("%s/private.idx", snac->basedir);
41     index_add(idx, id);
42 
43-    /* build the name for the linked copy in the private cache */
44-    xs *ofn = _object_fn(id);
45-    xs *l   = xs_split(ofn, "/");
46-    xs *cfn = xs_fmt("%s/private/%s", snac->basedir, xs_list_get(l, -1));
47-
48-    link(ofn, cfn);
49+    object_user_cache(snac, id, "private");
50 
51     if (xs_startswith(id, snac->actor)) {
52         /* add to the public index */
53         idx = xs_replace_i(idx, "private", "public");
54         index_add(idx, id);
55 
56-        /* add to the public cache */
57-        cfn = xs_replace_i(cfn, "private", "public");
58-        link(ofn, cfn);
59+        object_user_cache(snac, id, "public");
60     }
61 }
62