commit 6c6b5a3

default  ·  2022-11-25 16:26:12 +0000 UTC
parent 87d3ec2
Do hard links to objects in each user's public and private caches.
3 files changed,  +39, -3
M data.c
M data.c
+15, -2
 1@@ -14,7 +14,7 @@
 2 #include <sys/file.h>
 3 #include <fcntl.h>
 4 
 5-double db_layout = 2.3;
 6+double db_layout = 2.4;
 7 
 8 
 9 int db_upgrade(d_char **error);
10@@ -901,12 +901,25 @@ void timeline_object_add(snac *snac, const char *id, char *msg)
11 {
12     object_add(id, msg);
13 
14+    /* add to the private index */
15     xs *idx = xs_fmt("%s/private.idx", snac->basedir);
16     index_add(idx, id);
17 
18+    /* build the name for the linked copy in the private cache */
19+    xs *ofn = _object_fn(id);
20+    xs *l   = xs_split(ofn, "/");
21+    xs *cfn = xs_fmt("%s/private/%s", snac->basedir, xs_list_get(l, -1));
22+
23+    link(ofn, cfn);
24+
25     if (xs_startswith(id, snac->actor)) {
26-        idx = xs_replace_i(idx, "private.", "public.");
27+        /* add to the public index */
28+        idx = xs_replace_i(idx, "private", "public");
29         index_add(idx, id);
30+
31+        /* add to the public cache */
32+        cfn = xs_replace_i(cfn, "private", "public");
33+        link(ofn, cfn);
34     }
35 }
36 
+22, -0
 1@@ -106,6 +106,28 @@ int db_upgrade(d_char **error)
 2 
 3             nf = 2.3;
 4         }
 5+        else
 6+        if (f < 2.4) {
 7+            xs *users = user_list();
 8+            char *p, *v;
 9+
10+            p = users;
11+            while (xs_list_iter(&p, &v)) {
12+                snac snac;
13+
14+                if (user_open(&snac, v)) {
15+                    xs *dir = xs_fmt("%s/public", snac.basedir);
16+                    mkdir(dir, 0755);
17+
18+                    dir = xs_replace_i(dir, "public", "private");
19+                    mkdir(dir, 0755);
20+
21+                    user_free(&snac);
22+                }
23+            }
24+
25+            nf = 2.4;
26+        }
27 
28         if (f < nf) {
29             f          = nf;
+2, -1
 1@@ -238,7 +238,8 @@ int adduser(char *uid)
 2 
 3     const char *dirs[] = {
 4         "followers", "following", "local", "muted", "hidden",
 5-        "queue", "static", "timeline", "history", NULL };
 6+        "public", "private", "queue", "history",
 7+        "static", "timeline", NULL };
 8     int n;
 9 
10     for (n = 0; dirs[n]; n++) {