summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-02-23 18:42:38 +0100
committerGravatar default2023-02-23 18:42:38 +0100
commit285dbe1a5e5357ef5ce2110c60dc77e262d9e8cc (patch)
tree658bbdd30f90fa54223b0c85d4db07ef201bf1be
parentNew function index_gc(). (diff)
downloadpenes-snac2-285dbe1a5e5357ef5ce2110c60dc77e262d9e8cc.tar.gz
penes-snac2-285dbe1a5e5357ef5ce2110c60dc77e262d9e8cc.tar.xz
penes-snac2-285dbe1a5e5357ef5ce2110c60dc77e262d9e8cc.zip
Call index_gc() on the user indexes.
-rw-r--r--data.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/data.c b/data.c
index 8888d4a..9953e90 100644
--- a/data.c
+++ b/data.c
@@ -1642,20 +1642,27 @@ xs_dict *dequeue(const char *fn)
1642 1642
1643/** the purge **/ 1643/** the purge **/
1644 1644
1645static void _purge_file(const char *fn, time_t mt) 1645static int _purge_file(const char *fn, time_t mt)
1646/* purge fn if it's older than days */ 1646/* purge fn if it's older than days */
1647{ 1647{
1648 int ret = 0;
1649
1648 if (mtime(fn) < mt) { 1650 if (mtime(fn) < mt) {
1649 /* older than the minimum time: delete it */ 1651 /* older than the minimum time: delete it */
1650 unlink(fn); 1652 unlink(fn);
1651 srv_debug(1, xs_fmt("purged %s", fn)); 1653 srv_debug(1, xs_fmt("purged %s", fn));
1654 ret = 1;
1652 } 1655 }
1656
1657 return ret;
1653} 1658}
1654 1659
1655 1660
1656static void _purge_subdir(snac *snac, const char *subdir, int days) 1661static void _purge_subdir(snac *snac, const char *subdir, int days)
1657/* purges all files in subdir older than days */ 1662/* purges all files in subdir older than days */
1658{ 1663{
1664 int cnt = 0;
1665
1659 if (days) { 1666 if (days) {
1660 time_t mt = time(NULL) - days * 24 * 3600; 1667 time_t mt = time(NULL) - days * 24 * 3600;
1661 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir); 1668 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
@@ -1664,8 +1671,10 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
1664 1671
1665 p = list; 1672 p = list;
1666 while (xs_list_iter(&p, &v)) 1673 while (xs_list_iter(&p, &v))
1667 _purge_file(v, mt); 1674 cnt += _purge_file(v, mt);
1668 } 1675 }
1676
1677 snac_debug(snac, 0, xs_fmt("purge: ~/%s/ %d", subdir, cnt));
1669} 1678}
1670 1679
1671 1680
@@ -1675,6 +1684,7 @@ void purge_server(void)
1675 xs *spec = xs_fmt("%s/object/??", srv_basedir); 1684 xs *spec = xs_fmt("%s/object/??", srv_basedir);
1676 xs *dirs = xs_glob(spec, 0, 0); 1685 xs *dirs = xs_glob(spec, 0, 0);
1677 char *p, *v; 1686 char *p, *v;
1687 int cnt = 0;
1678 1688
1679 time_t mt = time(NULL) - 7 * 24 * 3600; 1689 time_t mt = time(NULL) - 7 * 24 * 3600;
1680 1690
@@ -1695,9 +1705,12 @@ void purge_server(void)
1695 char *md5 = xs_list_get(l, -1); 1705 char *md5 = xs_list_get(l, -1);
1696 1706
1697 object_del_by_md5(md5); 1707 object_del_by_md5(md5);
1708 cnt++;
1698 } 1709 }
1699 } 1710 }
1700 } 1711 }
1712
1713 srv_debug(0, xs_fmt("purge: global %d", cnt));
1701} 1714}
1702 1715
1703 1716
@@ -1706,6 +1719,7 @@ void purge_user(snac *snac)
1706{ 1719{
1707 int priv_days, pub_days, user_days = 0; 1720 int priv_days, pub_days, user_days = 0;
1708 char *v; 1721 char *v;
1722 int n;
1709 1723
1710 priv_days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days")); 1724 priv_days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
1711 pub_days = xs_number_get(xs_dict_get(srv_config, "local_purge_days")); 1725 pub_days = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
@@ -1727,6 +1741,14 @@ void purge_user(snac *snac)
1727 _purge_subdir(snac, "private", priv_days); 1741 _purge_subdir(snac, "private", priv_days);
1728 1742
1729 _purge_subdir(snac, "public", pub_days); 1743 _purge_subdir(snac, "public", pub_days);
1744
1745 const char *idxs[] = { "followers.idx", "private.idx", "public.idx", NULL };
1746
1747 for (n = 0; idxs[n]; n++) {
1748 xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]);
1749 int gc = index_gc(idx);
1750 snac_debug(snac, 0, xs_fmt("purge: %s %d", idx, gc));
1751 }
1730} 1752}
1731 1753
1732 1754