Skip to content

Commit 1f80d32

Browse files
authored
🩹 weekly dashboard μ•ˆ κ°€λŠ” 이슈 ν”½μŠ€ (#75)
promise.all 둜 300개 μ˜λ‹€κ°€ κΉƒν—™μ•‘μ…˜μ΄ OOMλ‚˜μ„œ 응닡을 λͺ»λ°›μ•„μ„œ ECONNRESET λ˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€.
1 parent 0d9c6c9 commit 1f80d32

5 files changed

Lines changed: 36 additions & 33 deletions

File tree

β€Ž.github/workflows/weekly-dashboard.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Node.js environment
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: '20.11.1'
20+
node-version: '20.15.0'
2121
cache: 'yarn'
2222

2323
# cron job을 μ‹€ν–‰ν•©λ‹ˆλ‹€.

β€Žpackage.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"dependencies": {
2222
"express": "4.19.2",
2323
"octokit": "4.0.2",
24-
"openai": "4.52.1"
24+
"openai": "4.52.1",
25+
"p-limit": "5.0.0"
2526
},
2627
"devDependencies": {
2728
"@types/express": "4.17.21",

β€Žsrc/infrastructures/implementMemberSlackRepository.tsβ€Ž

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pLimit from 'p-limit';
2+
13
import { Member } from '../entities/Member';
24

35
export const implementMemberSlackRepository = ({
@@ -14,30 +16,30 @@ export const implementMemberSlackRepository = ({
1416

1517
if (!users.ok) throw new Error('Failed to fetch users');
1618

19+
const limit = pLimit(10);
20+
21+
const fetchMemberProfile = async (member: { id: string }) => {
22+
const profile = await fetch(`https://slack.com/api/users.profile.get?user=${member.id}`, {
23+
method: 'GET',
24+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${slackAuthToken}` },
25+
}).then(
26+
(res) =>
27+
res.json() as Promise<
28+
{ ok: true; profile: { fields: { [githubField]?: { value: string } } } } | { ok: false }
29+
>,
30+
);
31+
32+
if (!profile.ok) throw new Error('Failed to fetch profile: ' + JSON.stringify(profile));
33+
34+
const githubUsername = profile.profile.fields[githubField]?.value;
35+
36+
if (!githubUsername) return [];
37+
38+
return [{ githubUsername: githubUsername.replace('https://github.com/', ''), slackUserId: member.id }];
39+
};
40+
1741
return {
18-
members: (
19-
await Promise.all(
20-
users.members.flatMap(async (member) => {
21-
const profile = await fetch(`https://slack.com/api/users.profile.get?user=${member.id}`, {
22-
method: 'GET',
23-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${slackAuthToken}` },
24-
}).then(
25-
(res) =>
26-
res.json() as Promise<
27-
{ ok: true; profile: { fields: { [githubField]?: { value: string } } } } | { ok: false }
28-
>,
29-
);
30-
31-
if (!profile.ok) throw new Error('Failed to fetch profile: ' + JSON.stringify(profile));
32-
33-
const githubUsername = profile.profile.fields[githubField]?.value;
34-
35-
if (!githubUsername) return [];
36-
37-
return [{ githubUsername: githubUsername.replace('https://github.com/', ''), slackUserId: member.id }];
38-
}),
39-
)
40-
).flat(),
42+
members: (await Promise.all(users.members.map((member) => limit(() => fetchMemberProfile(member))))).flat(),
4143
};
4244
},
4345
};

β€Žsrc/services/DashboardService.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const implementDashboardService = ({
129129
return {
130130
text: [
131131
divider,
132-
`${formatBold(`${formatEmoji('tada')} Top Contributors & Users Last Week`)} ${formatEmoji('blob-clap')}`,
132+
`${formatBold(`${formatEmoji('tada')} Top Contributors & Repositories Last Week`)} ${formatEmoji('blob-clap')}`,
133133
divider,
134134

135135
'\n',

β€Žyarn.lockβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,20 +1901,20 @@ optionator@^0.9.3:
19011901
type-check "^0.4.0"
19021902
word-wrap "^1.2.5"
19031903

1904+
p-limit@5.0.0, p-limit@^5.0.0:
1905+
version "5.0.0"
1906+
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985"
1907+
integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==
1908+
dependencies:
1909+
yocto-queue "^1.0.0"
1910+
19041911
p-limit@^3.0.2:
19051912
version "3.1.0"
19061913
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
19071914
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
19081915
dependencies:
19091916
yocto-queue "^0.1.0"
19101917

1911-
p-limit@^5.0.0:
1912-
version "5.0.0"
1913-
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985"
1914-
integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==
1915-
dependencies:
1916-
yocto-queue "^1.0.0"
1917-
19181918
p-locate@^5.0.0:
19191919
version "5.0.0"
19201920
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"

0 commit comments

Comments
Β (0)