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

@ -2,6 +2,7 @@ package sqlite
import (
"context"
"database/sql"
"strings"
"github.com/usememos/memos/store"
@ -104,3 +105,13 @@ func (d *Driver) DeleteMemoRelation(ctx context.Context, delete *store.DeleteMem
}
return nil
}
func vacuumMemoRelations(ctx context.Context, tx *sql.Tx) error {
if _, err := tx.ExecContext(ctx, `
DELETE FROM memo_relation
WHERE memo_id NOT IN (SELECT id FROM memo) OR related_memo_id NOT IN (SELECT id FROM memo)
`); err != nil {
return err
}
return nil
}