From 1ae82c9150277c79f34ee682eb0e18e293ce9ded Mon Sep 17 00:00:00 2001 From: Tung Wu Date: Tue, 4 Jun 2024 14:00:08 +0800 Subject: [PATCH] Fix user updated by import user api were not reindexed --- pkg/lib/userimport/service.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/lib/userimport/service.go b/pkg/lib/userimport/service.go index 18e9e84273..6e3e4c519b 100644 --- a/pkg/lib/userimport/service.go +++ b/pkg/lib/userimport/service.go @@ -81,6 +81,7 @@ type RolesGroupsCommands interface { } type ElasticsearchService interface { + MarkUsersAsReindexRequired(userIDs []string) error EnqueueReindexUserTask(userID string) error } @@ -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}) + default: + // Reindex is not required for other cases + } return nil }) if record != nil { @@ -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: