|
|
|
@ -10,9 +10,8 @@ import (
|
|
|
|
|
|
|
|
|
|
// Store provides database access to all raw objects.
|
|
|
|
|
type Store struct {
|
|
|
|
|
db *sql.DB
|
|
|
|
|
profile *profile.Profile
|
|
|
|
|
|
|
|
|
|
Profile *profile.Profile
|
|
|
|
|
db *sql.DB
|
|
|
|
|
systemSettingCache sync.Map // map[string]*systemSettingRaw
|
|
|
|
|
userCache sync.Map // map[int]*userRaw
|
|
|
|
|
userSettingCache sync.Map // map[string]*userSettingRaw
|
|
|
|
@ -24,8 +23,8 @@ type Store struct {
|
|
|
|
|
// New creates a new instance of Store.
|
|
|
|
|
func New(db *sql.DB, profile *profile.Profile) *Store {
|
|
|
|
|
return &Store{
|
|
|
|
|
Profile: profile,
|
|
|
|
|
db: db,
|
|
|
|
|
profile: profile,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -36,7 +35,7 @@ func (s *Store) Vacuum(ctx context.Context) error {
|
|
|
|
|
}
|
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
|
|
|
|
|
if err := vacuum(ctx, tx); err != nil {
|
|
|
|
|
if err := s.vacuumImpl(ctx, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -52,8 +51,7 @@ func (s *Store) Vacuum(ctx context.Context) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exec vacuum records in a transaction.
|
|
|
|
|
func vacuum(ctx context.Context, tx *sql.Tx) error {
|
|
|
|
|
func (s *Store) vacuumImpl(ctx context.Context, tx *sql.Tx) error {
|
|
|
|
|
if err := vacuumMemo(ctx, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -72,8 +70,10 @@ func vacuum(ctx context.Context, tx *sql.Tx) error {
|
|
|
|
|
if err := vacuumMemoResource(ctx, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := vacuumMemoRelations(ctx, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
if s.Profile.IsDev() {
|
|
|
|
|
if err := vacuumMemoRelations(ctx, tx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err := vacuumTag(ctx, tx); err != nil {
|
|
|
|
|
// Prevent revive warning.
|
|
|
|
|