Skip to content

Commit

Permalink
fix: use new context for log in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed Jun 14, 2024
1 parent 45ca958 commit 224218d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions core/relation/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ func (s Service) Create(ctx context.Context, rel RelationV2) (RelationV2, error)
return RelationV2{}, fmt.Errorf("%w: %s", ErrCreatingRelationInAuthzEngine, err.Error())
}

ctx = s.repository.WithoutTx(ctx)

go func() {
ctx = s.repository.WithoutTx(ctx)
ctx = context.WithoutCancel(ctx)
relationLogData := createdRelation.ToLogData()
actor := activity.Actor{ID: currentUser.ID, Email: currentUser.Email}
Expand Down
5 changes: 2 additions & 3 deletions core/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,9 @@ func (s Service) Create(ctx context.Context, res Resource) (Resource, error) {
return Resource{}, err
}

ctx = s.repository.WithoutTx(ctx)

go func() {
ctx = context.WithoutCancel(ctx)
ctx = s.repository.WithoutTx(ctx)
ctx := context.WithoutCancel(ctx)
resourceLogData := newResource.ToLogData()
actor := activity.Actor{ID: currentUser.ID, Email: currentUser.Email}
if err := s.activityService.Log(ctx, auditKeyResourceCreate, actor, resourceLogData); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions core/servicedata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ func (s Service) CreateKey(ctx context.Context, key Key) (Key, error) {
return Key{}, err
}

ctx = s.repository.WithoutTx(ctx)

go func() {
ctx = s.repository.WithoutTx(ctx)
ctx = context.WithoutCancel(ctx)
actor := activity.Actor{ID: currentUser.ID, Email: currentUser.Email}
if err := s.activityService.Log(ctx, auditKeyServiceDataKeyCreate, actor, key.ToKeyLogData()); err != nil {
Expand Down

0 comments on commit 224218d

Please sign in to comment.