Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions internal/integrations/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,38 +882,49 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
return
}

// Build an ID→User map from the cached users list to avoid N individual
// GetUserInfo calls (one per team member) inside the loop below.
cachedUsers, err := getCachedUsers(api)
if err != nil {
log.Printf("list-missing: getCachedUsers error: %v", err)
}
userByID := make(map[string]slack.User, len(cachedUsers))
for _, u := range cachedUsers {
userByID[u.ID] = u
}

type missingMember struct {
display string
userID string
}
var missing []missingMember
var missingIDs []string
for _, uid := range memberIDs {
user, err := api.GetUserInfo(uid)
u, found := userByID[uid]
nameCandidates := []string{uid}
if err == nil {
if user.Profile.DisplayName != "" {
nameCandidates = append(nameCandidates, user.Profile.DisplayName)
if found {
if u.Profile.DisplayName != "" {
nameCandidates = append(nameCandidates, u.Profile.DisplayName)
}
if user.RealName != "" {
nameCandidates = append(nameCandidates, user.RealName)
if u.RealName != "" {
nameCandidates = append(nameCandidates, u.RealName)
}
}
if memberReportedThisWeek(uid, nameCandidates, reportedAuthorIDs, reportedAuthors) {
continue
}
if err != nil {
if !found {
missing = append(missing, missingMember{display: uid, userID: uid})
missingIDs = append(missingIDs, uid)
continue
}

display := user.Profile.DisplayName
display := u.Profile.DisplayName
if display == "" {
display = user.RealName
display = u.RealName
}
if display == "" {
display = user.Name
display = u.Name
}
if display == "" {
display = uid
Expand Down