mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-24 00:23:38 +00:00
Added local timeline purging.
This commit is contained in:
parent
f197919acb
commit
0eb26f10e5
2 changed files with 29 additions and 32 deletions
58
data.c
58
data.c
|
@ -1130,42 +1130,38 @@ d_char *dequeue(snac *snac, char *fn)
|
|||
}
|
||||
|
||||
|
||||
static void _purge_subdir(snac *snac, const char *subdir, int days)
|
||||
/* purges all files in subdir older than days */
|
||||
{
|
||||
if (days) {
|
||||
time_t mt = time(NULL) - days * 24 * 3600;
|
||||
xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, subdir);
|
||||
xs *list = xs_glob(spec, 0, 0);
|
||||
char *p, *v;
|
||||
|
||||
p = list;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
if (mtime(v) < mt) {
|
||||
/* older than the minimum time: delete it */
|
||||
unlink(v);
|
||||
snac_debug(snac, 1, xs_fmt("purged %s", v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void purge(snac *snac)
|
||||
/* do the purge */
|
||||
{
|
||||
int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
|
||||
int days;
|
||||
|
||||
/* purge days set to 0? disable purging */
|
||||
if (tpd == 0) {
|
||||
/* well, enjoy your data drive exploding */
|
||||
return;
|
||||
}
|
||||
days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
|
||||
_purge_subdir(snac, "timeline", days);
|
||||
_purge_subdir(snac, "actors", days);
|
||||
|
||||
time_t mt = time(NULL) - tpd * 24 * 3600;
|
||||
xs *t_spec = xs_fmt("%s/timeline/" "*.json", snac->basedir);
|
||||
xs *t_list = xs_glob(t_spec, 0, 0);
|
||||
char *p, *v;
|
||||
|
||||
p = t_list;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
if (mtime(v) < mt) {
|
||||
/* older than the minimum time: delete it */
|
||||
unlink(v);
|
||||
snac_debug(snac, 1, xs_fmt("purged %s", v));
|
||||
}
|
||||
}
|
||||
|
||||
xs *a_spec = xs_fmt("%s/actors/" "*.json", snac->basedir);
|
||||
xs *a_list = xs_glob(a_spec, 0, 0);
|
||||
|
||||
p = a_list;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
if (mtime(v) < mt) {
|
||||
/* older than the minimum time: delete it */
|
||||
unlink(v);
|
||||
snac_debug(snac, 1, xs_fmt("purged %s", v));
|
||||
}
|
||||
}
|
||||
days = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
|
||||
_purge_subdir(snac, "local", days);
|
||||
}
|
||||
|
||||
|
||||
|
|
3
utils.c
3
utils.c
|
@ -24,7 +24,8 @@ const char *default_srv_config = "{"
|
|||
"\"queue_retry_max\": 10,"
|
||||
"\"cssurls\": [\"\"],"
|
||||
"\"max_timeline_entries\": 256,"
|
||||
"\"timeline_purge_days\": 120"
|
||||
"\"timeline_purge_days\": 120,"
|
||||
"\"local_purge_days\": 0"
|
||||
"}";
|
||||
|
||||
const char *default_css =
|
||||
|
|
Loading…
Reference in a new issue