chore: store vacuum and clean (#2293)

* Move all vacuum code into driver

* Remove db from Store
This commit is contained in:
Athurg Gooth
2023-09-27 09:27:31 +08:00
committed by GitHub
parent 9abf294eed
commit ca98367a0a
23 changed files with 239 additions and 238 deletions

View File

@ -181,5 +181,29 @@ func (d *Driver) DeleteResource(ctx context.Context, delete *store.DeleteResourc
return err
}
if err := d.Vacuum(ctx); err != nil {
// Prevent linter warning.
return err
}
return nil
}
func vacuumResource(ctx context.Context, tx *sql.Tx) error {
stmt := `
DELETE FROM
resource
WHERE
creator_id NOT IN (
SELECT
id
FROM
user
)`
_, err := tx.ExecContext(ctx, stmt)
if err != nil {
return err
}
return nil
}