MCPcopy Create free account
hub / github.com/dnote/dnote / StartPeriodicVacuum

Function StartPeriodicVacuum

pkg/server/database/database.go:127–138  ·  view source on GitHub ↗

StartPeriodicVacuum runs full VACUUM on a schedule to reclaim space and defragment. VACUUM acquires an exclusive lock and blocks all database operations briefly.

(db *gorm.DB, interval time.Duration)

Source from the content-addressed store, hash-verified

125// StartPeriodicVacuum runs full VACUUM on a schedule to reclaim space and defragment.
126// VACUUM acquires an exclusive lock and blocks all database operations briefly.
127func StartPeriodicVacuum(db *gorm.DB, interval time.Duration) {
128 go func() {
129 ticker := time.NewTicker(interval)
130 defer ticker.Stop()
131
132 for range ticker.C {
133 if err := db.Exec("VACUUM").Error; err != nil {
134 log.ErrorWrap(err, "VACUUM failed")
135 }
136 }
137 }()
138}

Callers 1

startCmdFunction · 0.92

Calls 2

ErrorWrapFunction · 0.92
ExecMethod · 0.65

Tested by

no test coverage detected