Skip to content

Commit 44642a0

Browse files
author
Codex
committed
Merge remote-tracking branch 'origin/main' into codex/fix-ticket-prefix-dedupe
2 parents ca89cdf + 3212225 commit 44642a0

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

internal/integrations/slack/slack.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,41 +882,49 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
882882
return
883883
}
884884

885+
// Build an ID→User map from the cached users list to avoid N individual
886+
// GetUserInfo calls (one per team member) inside the loop below.
887+
cachedUsers, err := getCachedUsers(api)
888+
if err != nil {
889+
log.Printf("list-missing: getCachedUsers error: %v", err)
890+
}
891+
userByID := make(map[string]slack.User, len(cachedUsers))
892+
for _, u := range cachedUsers {
893+
userByID[u.ID] = u
894+
}
895+
885896
type missingMember struct {
886897
display string
887898
userID string
888899
}
889900
var missing []missingMember
890901
var missingIDs []string
891902
for _, uid := range memberIDs {
892-
user, err := api.GetUserInfo(uid)
903+
u, found := userByID[uid]
893904
nameCandidates := []string{uid}
894-
if err == nil {
895-
if user.Profile.DisplayName != "" {
896-
nameCandidates = append(nameCandidates, user.Profile.DisplayName)
905+
if found {
906+
if u.Profile.DisplayName != "" {
907+
nameCandidates = append(nameCandidates, u.Profile.DisplayName)
897908
}
898-
if user.RealName != "" {
899-
nameCandidates = append(nameCandidates, user.RealName)
900-
}
901-
if user.Name != "" {
902-
nameCandidates = append(nameCandidates, user.Name)
909+
if u.RealName != "" {
910+
nameCandidates = append(nameCandidates, u.RealName)
903911
}
904912
}
905913
if memberReportedThisWeek(uid, nameCandidates, reportedAuthorIDs, reportedAuthors) {
906914
continue
907915
}
908-
if err != nil {
916+
if !found {
909917
missing = append(missing, missingMember{display: uid, userID: uid})
910918
missingIDs = append(missingIDs, uid)
911919
continue
912920
}
913921

914-
display := user.Profile.DisplayName
922+
display := u.Profile.DisplayName
915923
if display == "" {
916-
display = user.RealName
924+
display = u.RealName
917925
}
918926
if display == "" {
919-
display = user.Name
927+
display = u.Name
920928
}
921929
if display == "" {
922930
display = uid

0 commit comments

Comments
 (0)