Skip to content

Commit f6f9986

Browse files
authored
Merge pull request #35 from Mab879/vacuuming
Add database vacuuming
2 parents 85ae0f9 + ade29fc commit f6f9986

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cmd/cvetool/update.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,8 @@ func update(c *cli.Context) error {
7474
if err := lv.FetchUpdates(ctx); err != nil {
7575
return fmt.Errorf("error updating vulnerabilities: %v", err)
7676
}
77+
if err := matcherStore.VacuumDatabase(ctx); err != nil {
78+
return fmt.Errorf("error vacuum database : %v", err)
79+
}
7780
return nil
7881
}

datastore/sqlite_store.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,19 @@ func (ms *sqliteMatcherStore) GC(ctx context.Context, count int) (int64, error)
905905
return 0, nil
906906
}
907907

908+
func (ms *sqliteMatcherStore) VacuumDatabase(ctx context.Context) error {
909+
zlog.Debug(ctx).Msg(">>> VacuumDatabase")
910+
const (
911+
vacuum = "VACUUM;"
912+
)
913+
_, err := ms.conn.Exec(vacuum)
914+
if err != nil {
915+
return fmt.Errorf("failed to vacuum database: %v", err)
916+
}
917+
zlog.Info(ctx).Msg("finished database vacuum")
918+
return nil
919+
}
920+
908921
// RecordUpdaterStatus records that an updater is up to date with vulnerabilities at this time
909922
func (ms *sqliteMatcherStore) RecordUpdaterStatus(ctx context.Context, updaterName string, updateTime time.Time, fingerprint driver.Fingerprint, updaterError error) error {
910923
zlog.Debug(ctx).Msg(">>> RecordUpdaterStatus")

0 commit comments

Comments
 (0)