Skip to content

Commit 68c8930

Browse files
committed
apply suggestion to improve performance of realNameLookup method
1 parent f417859 commit 68c8930

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

components/slack_v2/slack_v2.app.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,11 @@ export default {
650650
return userNames;
651651
},
652652
async realNameLookup(ids = [], usernames = [], throwRateLimitError = true, args = {}) {
653+
const idSet = new Set(ids);
654+
const usernameSet = new Set(usernames);
653655
let cursor;
654656
const realNames = {};
657+
const targetCount = ids.length + usernames.length;
655658
do {
656659
const {
657660
members: users,
@@ -664,16 +667,16 @@ export default {
664667
});
665668

666669
for (const user of users) {
667-
if (ids.includes(user.id)) {
670+
if (idSet.has(user.id)) {
668671
realNames[user.id] = user.profile.real_name;
669672
}
670-
if (usernames.includes(user.name)) {
673+
if (usernameSet.has(user.name)) {
671674
realNames[user.name] = user.profile.real_name;
672675
}
673676
}
674677

675678
cursor = nextCursor;
676-
} while (cursor && Object.keys(realNames).length < (ids.length + usernames.length));
679+
} while (cursor && Object.keys(realNames).length < targetCount);
677680
return realNames;
678681
},
679682
async maybeAddAppToChannels(channelIds = []) {

0 commit comments

Comments
 (0)