From 6c6b5a30c4570ac0ace13e95e28a678c3720b899 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 25 Nov 2022 17:26:12 +0100 Subject: [PATCH] Do hard links to objects in each user's public and private caches. --- data.c | 17 +++++++++++++++-- upgrade.c | 22 ++++++++++++++++++++++ utils.c | 3 ++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/data.c b/data.c index 76ff51e..7f81202 100644 --- a/data.c +++ b/data.c @@ -14,7 +14,7 @@ #include #include -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); } } diff --git a/upgrade.c b/upgrade.c index 13f3fa1..786e0f9 100644 --- a/upgrade.c +++ b/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; diff --git a/utils.c b/utils.c index bf457b2..84b367f 100644 --- a/utils.c +++ b/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++) {