From c5ef9645e6061bac5844f94a220de1d150582c7b Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 22 Nov 2024 13:23:11 +1100 Subject: [PATCH] WAL truncating #769 --- front/maintenance.php | 6 ++++-- front/plugins/db_cleanup/script.py | 9 +++++++-- front/plugins/plugin_helper.py | 2 +- server/__main__.py | 7 +------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/front/maintenance.php b/front/maintenance.php index 1617dd5a..587cd1ea 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -40,7 +40,9 @@ // Size and last mod of DB ------------------------------------------------------ $nax_db = str_replace('front', 'db', getcwd()).'/app.db'; +$nax_wal = str_replace('front', 'db', getcwd()).'/app.db-wal'; $nax_db_size = number_format((filesize($nax_db) / 1000000),2,",",".") . ' MB'; +$nax_wal_size = number_format((filesize($nax_wal) / 1000000),2,",",".") . ' MB'; $nax_db_mod = date ("F d Y H:i:s", filemtime($nax_db)); @@ -104,13 +106,13 @@ $db->close();
- +
- + (wal: )
diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index d739299e..1260ebb0 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -204,13 +204,18 @@ def cleanup_database (dbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP conn.commit() + # Check WAL file size + cursor.execute("PRAGMA wal_checkpoint(TRUNCATE);") + cursor.execute("PRAGMA wal_checkpoint(FULL);") + + mylog('verbose', [f'[{pluginName}] WAL checkpoint executed to truncate file.']) + # Shrink DB mylog('verbose', [f'[{pluginName}] Shrink Database']) cursor.execute ("VACUUM;") # Close the database connection - conn.close() - + conn.close() #=============================================================================== diff --git a/front/plugins/plugin_helper.py b/front/plugins/plugin_helper.py index 9f105aef..9b1af2a5 100755 --- a/front/plugins/plugin_helper.py +++ b/front/plugins/plugin_helper.py @@ -44,7 +44,7 @@ def handleEmpty(input): return 'null' else: # Validate and sanitize message content - # Remove potentially problematic characters if string + # Remove potentially problematic characters in string if isinstance(input, str): input = re.sub(r'[^\x00-\x7F]+', ' ', input) input = input.replace('\n', '') # Removing new lines diff --git a/server/__main__.py b/server/__main__.py index d13e2cf6..c8a0e2f9 100755 --- a/server/__main__.py +++ b/server/__main__.py @@ -182,7 +182,7 @@ def main (): mylog('verbose', ['[Notification] No changes to report']) # Commit SQL - db.commitDB() + db.commitDB() # Footer @@ -198,11 +198,6 @@ def main (): - - - - - #=============================================================================== # BEGIN #===============================================================================