commit 285dbe1
default
·
2023-02-23 17:42:38 +0000 UTC
parent 307c942
Call index_gc() on the user indexes.
1 files changed,
+24,
-2
M
data.c
M
data.c
+24,
-2
1@@ -1642,20 +1642,27 @@ xs_dict *dequeue(const char *fn)
2
3 /** the purge **/
4
5-static void _purge_file(const char *fn, time_t mt)
6+static int _purge_file(const char *fn, time_t mt)
7 /* purge fn if it's older than days */
8 {
9+ int ret = 0;
10+
11 if (mtime(fn) < mt) {
12 /* older than the minimum time: delete it */
13 unlink(fn);
14 srv_debug(1, xs_fmt("purged %s", fn));
15+ ret = 1;
16 }
17+
18+ return ret;
19 }
20
21
22 static void _purge_subdir(snac *snac, const char *subdir, int days)
23 /* purges all files in subdir older than days */
24 {
25+ int cnt = 0;
26+
27 if (days) {
28 time_t mt = time(NULL) - days * 24 * 3600;
29 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
30@@ -1664,8 +1671,10 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
31
32 p = list;
33 while (xs_list_iter(&p, &v))
34- _purge_file(v, mt);
35+ cnt += _purge_file(v, mt);
36 }
37+
38+ snac_debug(snac, 0, xs_fmt("purge: ~/%s/ %d", subdir, cnt));
39 }
40
41
42@@ -1675,6 +1684,7 @@ void purge_server(void)
43 xs *spec = xs_fmt("%s/object/??", srv_basedir);
44 xs *dirs = xs_glob(spec, 0, 0);
45 char *p, *v;
46+ int cnt = 0;
47
48 time_t mt = time(NULL) - 7 * 24 * 3600;
49
50@@ -1695,9 +1705,12 @@ void purge_server(void)
51 char *md5 = xs_list_get(l, -1);
52
53 object_del_by_md5(md5);
54+ cnt++;
55 }
56 }
57 }
58+
59+ srv_debug(0, xs_fmt("purge: global %d", cnt));
60 }
61
62
63@@ -1706,6 +1719,7 @@ void purge_user(snac *snac)
64 {
65 int priv_days, pub_days, user_days = 0;
66 char *v;
67+ int n;
68
69 priv_days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
70 pub_days = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
71@@ -1727,6 +1741,14 @@ void purge_user(snac *snac)
72 _purge_subdir(snac, "private", priv_days);
73
74 _purge_subdir(snac, "public", pub_days);
75+
76+ const char *idxs[] = { "followers.idx", "private.idx", "public.idx", NULL };
77+
78+ for (n = 0; idxs[n]; n++) {
79+ xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]);
80+ int gc = index_gc(idx);
81+ snac_debug(snac, 0, xs_fmt("purge: %s %d", idx, gc));
82+ }
83 }
84
85