@ -30,6 +30,9 @@
# include <stdlib.h>
# include <stddef.h>
# include <sys/stat.h>
# include <unistd.h>
# define STATUSES_BY_URI "data / statuses / by-uri"
extern struct json_enum visibility_enum [ ] ;
@ -233,6 +236,9 @@ struct status* status_from_uri( const char* uri )
struct status * s = status_from_id ( atoi ( id_str ) ) ;
if ( s ) {
return s ;
} else {
// Status has been deleted, remove the index entry
ffdb_trie_remove ( " data/statuses/by-uri " , uri ) ;
}
free ( id_str ) ;
}
@ -451,6 +457,7 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
s - > poll = poll ;
}
s - > poll - > expires_at = act - > closed ;
sync_poll ( s , & act - > one_of ) ;
} else if ( act - > any_of . count > 0 ) {
if ( ! s - > poll ) {
@ -464,6 +471,7 @@ bool status_sync_from_activity_pub( struct status* s, struct ap_object* act )
s - > poll = poll ;
}
s - > poll - > expires_at = act - > closed ;
sync_poll ( s , & act - > any_of ) ;
}
@ -841,6 +849,7 @@ void status_delete( struct status* s )
char filename [ 512 ] ;
ffdb_trie_remove ( " data/statuses/stubs " , format ( filename , 512 , " %d " , s - > id ) ) ;
ffdb_trie_remove ( " data/statuses/by-uri " , s - > url ) ;
get_status_data_filename ( s - > id , filename , sizeof ( filename ) ) ;
remove ( filename ) ;
@ -1222,6 +1231,37 @@ void status_get_bookmarks( int offset, int limit, void* results_ptr )
void status_gc ( )
{
int count = ffdb_trie_count ( STATUSES_BY_URI ) ;
enum {
per_pass = 20 ,
} ;
struct {
char * * items ;
int count ;
} keys ;
printf ( " Checking and repairing uri-to-status index... \n " ) ;
int pages = ( count + per_pass - 1 ) / per_pass ;
for ( int i = 0 ; i < pages ; + + i ) {
printf ( " page %d of %d \n " , i , pages ) ;
memset ( & keys , 0 , sizeof ( keys ) ) ;
ffdb_trie_list ( STATUSES_BY_URI , i * per_pass , per_pass , & keys , NULL ) ;
// Check and repair index
//printf( "keys.count = %d\n", keys.count );
for ( int j = 0 ; j < keys . count ; + + j ) {
//printf( "processing %s\n", keys.items[j] );
status_free ( status_from_uri ( keys . items [ j ] ) ) ;
}
free ( keys . items ) ;
//sleep(1);
}
printf ( " done. \n " ) ;
/*
printf ( " Sweeping legacy uri->status_id index \n " ) ;
// Sweep legacy url to status id index