Write threads db in a transaction to avoid losing thread data.

This commit is contained in:
Retro_Guy 2023-09-01 02:46:37 -07:00
parent 4f95842cec
commit 993183eb84
2 changed files with 13 additions and 9 deletions

View File

@ -95,16 +95,21 @@ function thread_cache_save($headers, $group)
$database = $spooldir . '/' . $group . '-data.db3';
$table = "threads";
if ($dbh = threads_db_open($database, $table)) {
$drop = 'DROP TABLE IF EXISTS '. $table;
$drop = 'DROP TABLE IF EXISTS threads';
$drop_stmt = $dbh->prepare($drop);
$insert_sql = 'INSERT INTO ' . $table . '(headers) VALUES(?)';
$insert_stmt = $dbh->prepare($insert_sql);
$dbh->beginTransaction();
$drop_stmt->execute();
$dbh = null;
$dbh = threads_db_open($database, $table);
$sql = 'INSERT INTO ' . $table . '(headers) VALUES(?)';
$stmt = $dbh->prepare($sql);
$stmt->execute([
$dbh->exec("CREATE TABLE IF NOT EXISTS $table(
id INTEGER PRIMARY KEY,
headers TEXT,
unique (headers))");
$insert_stmt->execute([
serialize($headers)
]);
$dbh->commit();
$dbh = null;
}
}

View File

@ -1498,8 +1498,6 @@ function threads_db_open($database, $table = "threads")
id INTEGER PRIMARY KEY,
headers TEXT,
unique (headers))");
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_headers on ' . $table . '(headers)');
$stmt->execute();
return ($dbh);
}
@ -1823,7 +1821,8 @@ function add_to_history($group, $number, $msgid, $status, $statusdate, $statusre
$history_dbh = null;
}
function clear_history_by_group($group) {
function clear_history_by_group($group)
{
global $spooldir;
$history = $spooldir . '/history.db3';
$history_dbh = history_db_open($history);