@@ -882,38 +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 )
909+ if u .RealName != "" {
910+ nameCandidates = append (nameCandidates , u .RealName )
900911 }
901912 }
902913 if memberReportedThisWeek (uid , nameCandidates , reportedAuthorIDs , reportedAuthors ) {
903914 continue
904915 }
905- if err != nil {
916+ if ! found {
906917 missing = append (missing , missingMember {display : uid , userID : uid })
907918 missingIDs = append (missingIDs , uid )
908919 continue
909920 }
910921
911- display := user .Profile .DisplayName
922+ display := u .Profile .DisplayName
912923 if display == "" {
913- display = user .RealName
924+ display = u .RealName
914925 }
915926 if display == "" {
916- display = user .Name
927+ display = u .Name
917928 }
918929 if display == "" {
919930 display = uid
0 commit comments