mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Rewrite the entire config-related code to allow for changing data without having to restart. Hereby, we greatly reduce code duplication in the TOML routines so we won't have to touch tme in the future when adding additional options.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -35,16 +35,16 @@
|
||||
|
||||
static bool delete_old_queries_in_DB(sqlite3 *db)
|
||||
{
|
||||
const time_t timestamp = time(NULL) - config.database.maxDBdays * 86400;
|
||||
const time_t timestamp = time(NULL) - config.database.maxDBdays.v.i * 86400;
|
||||
SQL_bool(db, "DELETE FROM query_storage WHERE timestamp <= "TIME_T, timestamp);
|
||||
|
||||
// Get how many rows have been affected (deleted)
|
||||
const int affected = sqlite3_changes(db);
|
||||
|
||||
// Print final message only if there is a difference
|
||||
if((config.debug & DEBUG_DATABASE) || affected)
|
||||
if((config.debug.database.v.b) || affected)
|
||||
log_info("Size of %s is %.2f MB, deleted %i rows",
|
||||
config.files.database, 1e-6*get_FTL_db_filesize(), affected);
|
||||
config.files.database.v.s, 1e-6*get_FTL_db_filesize(), affected);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ void *DB_thread(void *val)
|
||||
// Save timestamp as we do not want to store immediately
|
||||
// to the database
|
||||
time_t before = time(NULL);
|
||||
time_t lastDBsave = before - before%config.database.DBinterval;
|
||||
time_t lastDBsave = before - before%config.database.DBinterval.v.ui;
|
||||
|
||||
// This thread runs until shutdown of the process. We keep this thread
|
||||
// running when pihole-FTL.db is corrupted because reloading of privacy
|
||||
@@ -88,13 +88,13 @@ void *DB_thread(void *val)
|
||||
break;
|
||||
|
||||
// Store queries in on-disk database
|
||||
if(now - lastDBsave >= (time_t)config.database.DBinterval)
|
||||
if(now - lastDBsave >= (time_t)config.database.DBinterval.v.ui)
|
||||
{
|
||||
// Update lastDBsave timer
|
||||
lastDBsave = now - now%config.database.DBinterval;
|
||||
lastDBsave = now - now%config.database.DBinterval.v.ui;
|
||||
|
||||
// Save data to database (if enabled)
|
||||
if(config.database.DBexport)
|
||||
if(config.database.DBexport.v.b)
|
||||
{
|
||||
DBOPEN_OR_AGAIN();
|
||||
lock_shm();
|
||||
@@ -106,7 +106,7 @@ void *DB_thread(void *val)
|
||||
break;
|
||||
|
||||
// Check if GC should be done on the database
|
||||
if(DBdeleteoldqueries && config.database.maxDBdays != -1)
|
||||
if(DBdeleteoldqueries && config.database.maxDBdays.v.i != -1)
|
||||
{
|
||||
// No thread locks needed
|
||||
delete_old_queries_in_DB(db);
|
||||
@@ -117,7 +117,7 @@ void *DB_thread(void *val)
|
||||
}
|
||||
|
||||
// Parse neighbor cache (fill network table) if enabled
|
||||
if (config.database.network.parseARPcache)
|
||||
if (config.database.network.parseARPcache.v.b)
|
||||
set_event(PARSE_NEIGHBOR_CACHE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user