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
tung2744 committed Jun 4, 2024
1 parent 9a65afa commit 1ae82c9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 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,22 @@ 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
s.Elasticsearch.MarkUsersAsReindexRequired([]string{detail.UserID})

Check failure on line 142 in pkg/lib/userimport/service.go

View workflow job for this annotation

GitHub Actions / authgear-test

Error return value of `s.Elasticsearch.MarkUsersAsReindexRequired` is not checked (errcheck)
default:
// Reindex is not required for other cases
}
return nil
})
if record != nil {
Expand All @@ -149,15 +160,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 1ae82c9

Please sign in to comment.