Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add vacuum memo relation to dev guard #1644

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion store/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions store/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion store/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 9 additions & 9 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand All @@ -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
}

Expand All @@ -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
}
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion store/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down