chore: add vacuum memo relation to dev guard (#1644)

* chore: add vacuum memo relation to dev guard

* chore: update
This commit is contained in:
boojack 2023-05-09 09:02:59 +08:00 committed by GitHub
parent 84546ff11c
commit 9b8d69b2dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 14 deletions

View File

@ -38,7 +38,7 @@ func (raw *activityRaw) toActivity() *api.Activity {
// CreateActivity creates an instance of Activity.
func (s *Store) CreateActivity(ctx context.Context, create *api.ActivityCreate) (*api.Activity, error) {
if s.profile.Mode == "prod" {
if s.Profile.Mode == "prod" {
return nil, nil
}

View File

@ -53,7 +53,7 @@ func (s *Store) ComposeMemo(ctx context.Context, memo *api.Memo) (*api.Memo, err
if err := s.ComposeMemoResourceList(ctx, memo); err != nil {
return nil, err
}
if s.profile.IsDev() {
if s.Profile.IsDev() {
if err := s.ComposeMemoRelationList(ctx, memo); err != nil {
return nil, err
}
@ -184,7 +184,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *api.MemoDelete) error {
if err := deleteMemo(ctx, tx, delete); err != nil {
return FormatError(err)
}
if err := vacuum(ctx, tx); err != nil {
if err := s.vacuumImpl(ctx, tx); err != nil {
return err
}

View File

@ -160,7 +160,7 @@ func (s *Store) DeleteResource(ctx context.Context, delete *api.ResourceDelete)
if err := deleteResource(ctx, tx, delete); err != nil {
return err
}
if err := vacuum(ctx, tx); err != nil {
if err := s.vacuumImpl(ctx, tx); err != nil {
return err
}

View File

@ -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.

View File

@ -163,7 +163,7 @@ func (s *Store) DeleteUser(ctx context.Context, delete *api.UserDelete) error {
if err := deleteUser(ctx, tx, delete); err != nil {
return err
}
if err := vacuum(ctx, tx); err != nil {
if err := s.vacuumImpl(ctx, tx); err != nil {
return err
}