Reduce outbox processing load by advancing the TAIL to skip sent/canceled outbox items

master
teknomunk 1 year ago
parent 9721eb53d8
commit 63b8bc5141

@ -20,7 +20,7 @@
#include <string.h>
#include <unistd.h>
static bool process_envelope( int id )
static bool process_envelope( struct outbox_envelope* env )
{
bool result = false;
char* postdata = NULL;
@ -28,17 +28,10 @@ static bool process_envelope( int id )
FILE* f = NULL;
struct ap_activity* act = NULL;
// Get next outbox item
struct outbox_envelope* env = outbox_envelope_from_id( id );
if( !env ) {
printf( "? No envelope\n" );
goto failed;
}
if( env->sent ) { return false; }
if( env->retry_after > time(NULL) ) { return false; }
printf( "Processing outbox/%d.json\n", id );
printf( "Processing outbox/%d.json\n", env->id );
printf( "account_id=%d\n", env->account_id );
printf( "activity_id=%d\n", env->activity_id );
@ -136,7 +129,6 @@ static bool process_envelope( int id )
cleanup:
ap_activity_free(act);
account_free(to_account);
outbox_envelope_free(env);
free(postdata);
crypto_keys_free(keys);
@ -157,10 +149,21 @@ static bool process_one()
int tail = fs_list_get("data/outbox/TAIL");
bool result = false;
for( int i = tail + 1; i <= head; ++i ) {
if( process_envelope(i) ) {
printf( "Done with outbox/%d.json\n", i );
result = true;
//fs_list_set( "data/outbox/TAIL", tail + 1 );
struct outbox_envelope* env = outbox_envelope_from_id( i );
if( !env ) {
// Envelope file doesn't exist, advance tail
fs_list_set( "data/outbox/TAIL", i );
tail += 1;
} else if( env ) {
if( env->sent && i == tail+1 ) {
// Envelope already sent, advance tail
fs_list_set( "data/outbox/TAIL", i );
tail += 1;
} else if( process_envelope(env) ) {
printf( "Done with outbox/%d.json\n", i );
result = true;
}
outbox_envelope_free(env);
}
}

Loading…
Cancel
Save