update
This commit is contained in:
@@ -51,6 +51,21 @@ impl Database {
|
||||
Ok(db)
|
||||
}
|
||||
|
||||
/// 执行 WAL checkpoint(TRUNCATE),将 WAL 完全合并回主文件并清理 -wal / -shm 文件
|
||||
///
|
||||
/// 应在服务优雅关闭时调用,确保数据库文件处于干净一致的状态,
|
||||
/// 避免下次启动时 WAL 恢复带来的额外开销。
|
||||
pub async fn wal_checkpoint(&self) {
|
||||
let _guard = self.write_lock.lock().await;
|
||||
// wal_checkpoint 返回一行 (busy, log, checkpointed),只关注结果忽略返回值
|
||||
match sqlx::query("PRAGMA wal_checkpoint(TRUNCATE)")
|
||||
.execute(&self.pool).await
|
||||
{
|
||||
Ok(_) => println!("[DB] WAL checkpoint(TRUNCATE) 完成,数据库文件已合并"),
|
||||
Err(e) => eprintln!("[DB] WAL checkpoint 失败: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
/// 确保 image_count 字段存在
|
||||
async fn ensure_image_count_field(&self) -> Result<(), sqlx::Error> {
|
||||
let has_col = sqlx::query_scalar::<_, i64>(
|
||||
|
||||
Reference in New Issue
Block a user