Skip to content

Commit

Permalink
Fix user updated by import user api were not reindexed
Browse files Browse the repository at this point in the history
  • Loading branch information
louischan-oursky committed Jun 4, 2024
2 parents 9a65afa + b8c402e commit 7dfbc25
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/lib/userimport/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type RolesGroupsCommands interface {
}

type ElasticsearchService interface {
MarkUsersAsReindexRequired(userIDs []string) error
EnqueueReindexUserTask(userID string) error
}

Expand Down Expand Up @@ -126,12 +127,25 @@ func (s *UserImportService) ImportRecords(ctx context.Context, request *Request)
}

var record Record
shouldReindexUser := false
err := s.AppDatabase.WithTx(func() error {
var err error
record, err = s.ImportRecordInTxn(ctx, &detail, options, rawMessage)
if err != nil {
return err
}
switch detail.Outcome {
case OutcomeInserted:
fallthrough
case OutcomeUpdated:
shouldReindexUser = true
err = s.Elasticsearch.MarkUsersAsReindexRequired([]string{detail.UserID})
if err != nil {
return err
}
default:
// Reindex is not required for other cases
}
return nil
})
if record != nil {
Expand All @@ -149,15 +163,12 @@ func (s *UserImportService) ImportRecords(ctx context.Context, request *Request)
}

result.Details = append(result.Details, detail)
shouldReindexUser := false

switch detail.Outcome {
case OutcomeInserted:
result.Summary.Inserted += 1
shouldReindexUser = true
case OutcomeUpdated:
result.Summary.Updated += 1
shouldReindexUser = true
case OutcomeSkipped:
result.Summary.Skipped += 1
case OutcomeFailed:
Expand Down

0 comments on commit 7dfbc25

Please sign in to comment.