File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 88 "html/template"
99 "io"
1010 "log"
11- "math/rand"
1211 "net/http"
1312 "os"
1413 "strconv"
@@ -429,6 +428,7 @@ func DeleteAccountHandler(w http.ResponseWriter, r *http.Request) {
429428}
430429
431430// Delete invalid pastes
431+ var vacuumCounter int // Track no of deletions to trigger VACUUM
432432func DeleteExpiredPastes () {
433433 db .DB .Where ("expiration IS NOT NULL AND expiration < ?" , time .Now ()).Delete (& models.Paste {})
434434
@@ -440,8 +440,12 @@ func DeleteExpiredPastes() {
440440 }
441441 threshold := time .Now ().AddDate (0 , 0 , - retention )
442442 result := db .DB .Unscoped ().Where ("deleted_at IS NOT NULL AND deleted_at < ?" , threshold ).Delete (& models.Paste {})
443- if result .RowsAffected > 0 && rand .Intn (5 ) == 0 { // random sampling 20% chance
444- db .DB .Exec ("VACUUM;" )
443+ if result .RowsAffected > 0 {
444+ vacuumCounter ++
445+ if vacuumCounter >= 5 { // every 5 deletions
446+ db .DB .Exec ("VACUUM;" )
447+ vacuumCounter = 0
448+ }
445449 }
446450 }()
447451}
You can’t perform that action at this time.
0 commit comments