Unverified Commit 9b8d69b2 authored by boojack's avatar boojack Committed by GitHub

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

* chore: add vacuum memo relation to dev guard

* chore: update
parent 84546ff1
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -10,9 +10,8 @@ import (
// Store provides database access to all raw objects.
type Store struct {
Profile *profile.Profile
db *sql.DB
profile *profile.Profile
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,9 +70,11 @@ func vacuum(ctx context.Context, tx *sql.Tx) error {
if err := vacuumMemoResource(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.
return err
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment