startSQLiteMaintenance runs periodic WAL checkpoint and VACUUM on both the main database and the objects database (if present). This reclaims disk space from deleted rows/blobs and keeps the WAL file from growing unbounded.
()
| 150 | // main database and the objects database (if present). This reclaims disk space |
| 151 | // from deleted rows/blobs and keeps the WAL file from growing unbounded. |
| 152 | func (s *sqlDatabase) startSQLiteMaintenance() { |
| 153 | ticker := time.NewTicker(24 * time.Hour) |
| 154 | defer ticker.Stop() |
| 155 | |
| 156 | for { |
| 157 | select { |
| 158 | case <-s.ctx.Done(): |
| 159 | return |
| 160 | case <-ticker.C: |
| 161 | s.runSQLiteMaintenance(s.conn, "main") |
| 162 | if s.objectsConn != nil { |
| 163 | s.runSQLiteMaintenance(s.objectsConn, "objects") |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | func (s *sqlDatabase) runSQLiteMaintenance(conn *gorm.DB, dbName string) { |
| 170 | if err := conn.Exec("PRAGMA wal_checkpoint(TRUNCATE)").Error; err != nil { |
no test coverage detected