Browse Source

Do hard links to objects in each user's public and private caches.

default 2 years ago
parent
commit
6c6b5a30c4
3 changed files with 39 additions and 3 deletions
  1. 15 2
      data.c
  2. 22 0
      upgrade.c
  3. 2 1
      utils.c

+ 15 - 2
data.c

@@ -14,7 +14,7 @@
 #include <sys/file.h>
 #include <fcntl.h>
 
-double db_layout = 2.3;
+double db_layout = 2.4;
 
 
 int db_upgrade(d_char **error);
@@ -901,12 +901,25 @@ void timeline_object_add(snac *snac, const char *id, char *msg)
 {
     object_add(id, msg);
 
+    /* add to the private index */
     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);
+
     if (xs_startswith(id, snac->actor)) {
-        idx = xs_replace_i(idx, "private.", "public.");
+        /* 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);
     }
 }
 

+ 22 - 0
upgrade.c

@@ -106,6 +106,28 @@ int db_upgrade(d_char **error)
 
             nf = 2.3;
         }
+        else
+        if (f < 2.4) {
+            xs *users = user_list();
+            char *p, *v;
+
+            p = users;
+            while (xs_list_iter(&p, &v)) {
+                snac snac;
+
+                if (user_open(&snac, v)) {
+                    xs *dir = xs_fmt("%s/public", snac.basedir);
+                    mkdir(dir, 0755);
+
+                    dir = xs_replace_i(dir, "public", "private");
+                    mkdir(dir, 0755);
+
+                    user_free(&snac);
+                }
+            }
+
+            nf = 2.4;
+        }
 
         if (f < nf) {
             f          = nf;

+ 2 - 1
utils.c

@@ -238,7 +238,8 @@ int adduser(char *uid)
 
     const char *dirs[] = {
         "followers", "following", "local", "muted", "hidden",
-        "queue", "static", "timeline", "history", NULL };
+        "public", "private", "queue", "history",
+        "static", "timeline", NULL };
     int n;
 
     for (n = 0; dirs[n]; n++) {