INNER CODE UNIT · Go
ForceDBSync
OpenListTeam/OpenList-Mobile · openlist-lib/openlistlib/server.go:75
func ForceDBSync() error {
log.Info("Forcing database sync (WAL checkpoint)...")
// Get the database instance and execute WAL checkpoint
gormDB := db.GetDb()
if gormDB != nil {
sqlDB, err := gormDB.DB()
if err != nil {
log.Errorf("Failed to get database connection: %v", err)
return err
}
// Execute WAL checkpoint with TRUNCATE mode to force sync and remove WAL files
_, err = sqlDB.Exec("PRAGMA wal_checkpoint(TRUNCATE)")
if err != nil {
log.Errorf("Failed to execute WAL checkpoint: %v", err)
return err
}