From c3e42624754bc18ba50b1149c56b8c5ec3e46c9a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 19 May 2022 17:29:15 -0400 Subject: [PATCH] fix: removing VACUUM to speedup db operations --- waku/persistence/store.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/waku/persistence/store.go b/waku/persistence/store.go index c9090129..3ca6e709 100644 --- a/waku/persistence/store.go +++ b/waku/persistence/store.go @@ -113,28 +113,30 @@ func (d *DBStore) createTable() error { } func (d *DBStore) cleanOlderRecords() error { + d.log.Debug("Cleaning older records...") + // Delete older messages if d.maxDuration > 0 { + start := time.Now() sqlStmt := `DELETE FROM message WHERE receiverTimestamp < ?` _, err := d.db.Exec(sqlStmt, utils.GetUnixEpochFrom(time.Now().Add(-d.maxDuration))) if err != nil { return err } + elapsed := time.Since(start) + d.log.Debug(fmt.Sprintf("Deleting older records from the DB took %s", elapsed)) } // Limit number of records to a max N if d.maxMessages > 0 { + start := time.Now() sqlStmt := `DELETE FROM message WHERE id IN (SELECT id FROM message ORDER BY receiverTimestamp DESC LIMIT -1 OFFSET ?)` _, err := d.db.Exec(sqlStmt, d.maxMessages) if err != nil { return err } - } - - // reduce the size of the DB file after the delete operation. See: https://www.sqlite.org/lang_vacuum.html - _, err := d.db.Exec("VACUUM") - if err != nil { - return err + elapsed := time.Since(start) + d.log.Debug(fmt.Sprintf("Deleting excess records from the DB took %s", elapsed)) } return nil