add gc for db

This commit is contained in:
janis
2023-08-22 19:21:40 +02:00
parent 64af566b86
commit eacaebd84b
2 changed files with 40 additions and 1 deletions

View File

@@ -185,5 +185,30 @@ module.exports.deleteJSONDataSimple = ( db, identifier ) => {
} );
};
const gc = () => {
// this function acts as the database garbage collector. TicketTimeout can be changed from the GUI. TODO: Add
this.getData( 'temp' ).then( tempData => {
let data = tempData;
console.info( 'Garbage Collecting' );
for ( let item in data ) {
if ( new Date( data[ item ][ 'timestamp' ] ).getTime() + ( parseInt( settings.ticketTimeout ) * 1000 ) > new Date().getTime() ) {
delete data[ item ];
console.debug( 'Garbage collected a session' );
}
}
} );
};
/*
Here, GC-Duty is scheduled to run every so often (defined in settings.config.json file, no GUI setting available.
If you are a developer and are thinking about adding a GUI setting for this, please consider that this is a
advanced setting and many people might not understand what it changes. The config file is mentioned in the
"advanced settings" section of the admin panel documentation where all the available settings in the config file
are explained in some detail.)
*/
setInterval( () => {
gc();
}, parseInt( settings.gcInterval ) );
// TODO: Build garbage collector for DB (parse DB every so often (get from settings)
// and delete all items where timestamp is older than a certain amount of time (get from settings))