feat: enhance database maintenance with error handling and logging for VACUUM and PRAGMA optimize operations
This commit is contained in:
parent
fd2ebce29e
commit
7eeee665ee
@ -34,8 +34,24 @@ func cleanTmpFolder() {
|
||||
}
|
||||
|
||||
func cleanDB() {
|
||||
if time.Now().Weekday() == time.Sunday && time.Now().Hour() < 1 {
|
||||
db := sqlite3.GetDB()
|
||||
db.Exec("VACUUM")
|
||||
if time.Now().Weekday() == time.Sunday && time.Now().Hour() < 1 {
|
||||
start := time.Now()
|
||||
_, err := db.Exec("VACUUM")
|
||||
if err != nil {
|
||||
log.Printf("清理数据库失败: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("数据库清理完成,耗时: %v", time.Since(start))
|
||||
}
|
||||
now := time.Now()
|
||||
if now.Hour() == 1 && now.Minute() < 10 {
|
||||
start := time.Now()
|
||||
_, err := db.Exec("PRAGMA optimize")
|
||||
if err != nil {
|
||||
log.Printf("优化数据库失败: %v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("数据库优化完成,耗时: %v", time.Since(start))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user