Skip to content

Commit

Permalink
Add new method for vacuuming a c1z db. Vacuum after removing old gene…
Browse files Browse the repository at this point in the history
…rations. (#79)
  • Loading branch information
jirwin authored Oct 19, 2023
1 parent 8c578cb commit df47609
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/dotc1z/sync_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ func (c *C1File) Cleanup(ctx context.Context) error {
l.Info("Removed old sync data.", zap.String("sync_date", ret[i].EndedAt.Format(time.RFC3339)), zap.String("sync_id", ret[i].ID))
}

err = c.Vacuum(ctx)
if err != nil {
return err
}

c.dbUpdated = true

return nil
}

Expand Down Expand Up @@ -457,3 +464,20 @@ func (c *C1File) DeleteSyncRun(ctx context.Context, syncID string) error {

return nil
}

// Vacuum runs a VACUUM on the database to reclaim space.
func (c *C1File) Vacuum(ctx context.Context) error {
err := c.validateDb(ctx)
if err != nil {
return err
}

_, err = c.rawDb.ExecContext(ctx, "VACUUM")
if err != nil {
return err
}

c.dbUpdated = true

return nil
}

0 comments on commit df47609

Please sign in to comment.