WAL truncating #769

This commit is contained in:
jokob-sk
2024-11-22 13:23:11 +11:00
parent eee84b23b8
commit c5ef9645e6
4 changed files with 13 additions and 11 deletions

View File

@@ -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();
<div class="db_info_table_row">
<div class="db_info_table_cell" style="min-width: 140px"><?= lang('Maintenance_database_path');?></div>
<div class="db_info_table_cell">
<?php echo $nax_db;?>
<?php echo $nax_db;?>
</div>
</div>
<div class="db_info_table_row">
<div class="db_info_table_cell"><?= lang('Maintenance_database_size');?></div>
<div class="db_info_table_cell">
<?php echo $nax_db_size;?>
<?php echo $nax_db_size;?> (wal: <?php echo $nax_wal_size;?>)
</div>
</div>
<div class="db_info_table_row">

View File

@@ -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()
#===============================================================================

View File

@@ -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