Start implementation of garbage collection of older posts, fix to,cc,bcc parse error when a single value is present, fix Accept header value, add status removal functions
parent
c6f8df2244
commit
9b361dd2d3
@ -1 +1 @@
|
||||
Subproject commit b5165d7553f1b247212f4ee4d095d8eadb77d70f
|
||||
Subproject commit 34af1bef81911b7206cc8c514c09022de1f74695
|
@ -1 +1 @@
|
||||
Subproject commit 36c3fb214952ab71a0f3ee7c235a78c19c2ac5a8
|
||||
Subproject commit ad7f0125cb4feadb222290149f06ce9166f429a4
|
@ -0,0 +1,147 @@
|
||||
#include "gc.h"
|
||||
|
||||
#include "ffdb/fs_list.h"
|
||||
|
||||
#include "model/status.h"
|
||||
#include "model/account.h"
|
||||
|
||||
#include "timeline.h"
|
||||
|
||||
void mark_post( int status_id, bool force )
|
||||
{
|
||||
struct status* s = status_from_id( status_id );
|
||||
if( !s ) { return; }
|
||||
if( s->mark && !force ) {
|
||||
// Already marked
|
||||
status_free(s);
|
||||
return;
|
||||
}
|
||||
|
||||
s->mark = true;
|
||||
status_save(s);
|
||||
|
||||
// Flood fill to keep all related posts alive
|
||||
if( s->repost_id ) {
|
||||
mark_post( s->repost_id, false );
|
||||
}
|
||||
if( s->in_reply_to ) {
|
||||
mark_post( s->in_reply_to, false );
|
||||
}
|
||||
for( int i = 0; i < s->replies.count; ++i ) {
|
||||
mark_post( s->replies.items[i], false );
|
||||
}
|
||||
|
||||
status_free(s);
|
||||
}
|
||||
|
||||
void gc_run()
|
||||
{
|
||||
int head = fs_list_get( "data/statuses/HEAD" );
|
||||
int tail = fs_list_get( "data/statuses/TAIL" );
|
||||
|
||||
// Clear all marks
|
||||
printf( "Clearing marks..." );
|
||||
fflush(stdout);
|
||||
for( int i = tail; i < head; ++i ) {
|
||||
struct status* s = status_from_id(i);
|
||||
if( !s ) {
|
||||
if( i == tail ) {
|
||||
tail += 1;
|
||||
}
|
||||
} else {
|
||||
if( s->mark ) {
|
||||
s->mark = false;
|
||||
status_save(s);
|
||||
}
|
||||
status_free(s);
|
||||
}
|
||||
}
|
||||
printf( "done.\n" );
|
||||
fflush(stdout);
|
||||
|
||||
// Save tail position
|
||||
fs_list_set( "data/statuses/TAIL", tail );
|
||||
|
||||
// Mark posts to keep
|
||||
printf( "Mark posts to keep..." );
|
||||
fflush(stdout);
|
||||
for( int i = tail; i < head; ++i ) {
|
||||
struct status* s = status_from_id(i);
|
||||
if( !s ) { continue; }
|
||||
|
||||
if( s->published > time(NULL) - 3600 * 24 * 2 ) { // keep all posts in the last 2 days
|
||||
s->mark = true;
|
||||
} else if( s->account_id == owner_account_id ) { // Keep all owner posts
|
||||
if( s->repost_id ) {
|
||||
s->mark = true;
|
||||
}
|
||||
} else if( s->bookmarked ) {
|
||||
s->mark = true;
|
||||
} else if( s->pinned ) { // Keep pinned posts regardless of age
|
||||
s->mark = true;
|
||||
}
|
||||
|
||||
if( s->mark ) {
|
||||
mark_post( s->id, true );
|
||||
status_save(s);
|
||||
}
|
||||
|
||||
status_free(s);
|
||||
}
|
||||
printf( "done.\n");
|
||||
fflush(stdout);
|
||||
|
||||
printf( "Sweeping..." );
|
||||
fflush(stdout);
|
||||
int to_keep = 0;
|
||||
for( int i = tail; i < head; ++i ) {
|
||||
struct status* s = status_from_id(i);
|
||||
bool delete = true;
|
||||
if( !s ) {
|
||||
if( i == tail ) {
|
||||
tail += 1;
|
||||
}
|
||||
} else {
|
||||
if( s->published > time(NULL) - 3600 * 24 * 2 ) { // keep all posts in the last 2 days
|
||||
delete = false;
|
||||
} else if( s->mark ) {
|
||||
delete = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( s ) {
|
||||
if( delete ) {
|
||||
status_delete(s);
|
||||
} else {
|
||||
status_free(s);
|
||||
}
|
||||
} else {
|
||||
to_keep += 1;
|
||||
}
|
||||
}
|
||||
printf( "done. Would keep %d posts.\n", to_keep );
|
||||
fflush(stdout);
|
||||
|
||||
// Clear all marks once we are done
|
||||
printf( "Clearing marks..." );
|
||||
for( int i = tail; i < head; ++i ) {
|
||||
struct status* s = status_from_id(i);
|
||||
if( !s ) {
|
||||
if( i == tail ) {
|
||||
tail += 1;
|
||||
}
|
||||
} else {
|
||||
if( s->mark ) {
|
||||
s->mark = false;
|
||||
status_save(s);
|
||||
}
|
||||
status_free(s);
|
||||
}
|
||||
}
|
||||
printf( "done.\n" );
|
||||
fflush(stdout);
|
||||
|
||||
// Save tail position
|
||||
fs_list_set( "data/statuses/TAIL", tail );
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void gc_run();
|
||||
|
Loading…
Reference in new issue