You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.0 KiB
C

#include "fetch.h"
// Model
#include "model/status.h"
#include "model/account.h"
// Submodules
#include "ffdb/trie.h"
#include "util/time.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define STUBS "data/statuses/stubs"
extern bool terminate;
static void process_fetch_once()
{
int count = ffdb_trie_count(STUBS);
int removed = 0;
int synced = 0;
int failed_syncs = 0;
time_t now = time(NULL);
for( int i = 0; i < count; ++i ) {
if( terminate ) { return; };
int idx = count - i - 1;
char* key = NULL;
char* value = NULL;
if( !ffdb_trie_get_index( STUBS, idx, &key, &value ) ) {
//printf( "Unable to get STUBS[%d], skipping\n", idx );
continue;
}
//printf( "STUBS[%d]: %s = %s\n", idx, key, value );
struct status* s = status_from_id( atoi(key) );
if( !s ) {
printf( "Unable to load status with id %s\n", key );
remove:
ffdb_trie_remove( STUBS, key );
removed += 1;
} else {
if( !status_sync(s) ) {
if( now - s->published > 60*60*24*5 ) {
// Older than 5 days
printf( "Status %d older than 5 days old, removing from stub list\n", s->id );
goto remove;
}
failed_syncs += 1;
} else {
synced += 1;
}
status_save(s);
}
status_free(s);
free(key);
free(value);
}
printf( "%d stub statuses, synced %d (%d failed), removed %d\n", count, synced, failed_syncs, removed );
printf( "new count = %d\n", ffdb_trie_count(STUBS) );
}
/*
static void process_account_sync_once()
{
for( int i = 0; i < 10; ++i ) {
struct account* a = account_load_next_update();
if( !a ) { continue; }
if( time(NULL) >= a->next_update ) {
account_sync_from_activity_pub( a->id, true );
} else {
char buffer[512];
rfc3339_time_string( a->next_update, buffer,512 );
printf( "Account not yet due for update. Holding until %s\n", buffer );
}
account_free(a);
return;
}
}
*/
void process_fetch()
{
while(true) {
process_fetch_once();
//process_account_sync_once();
for( int i = 0; i < 30; ++i ) {
if( terminate ) { return; };
sleep(1);
}
}
}