Skip to content

Commit 13f67f8

Browse files
committed
perf: concurrently run report tasks
1 parent 5371232 commit 13f67f8

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

server/api/device/[id]/report/custom/index.post.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,37 @@ export default defineEventHandler(async (event) => {
3131
const baseUrl = config.public.auth.baseUrl
3232
const deviceUrl = joinURL(baseUrl, 'devices', deviceId)
3333

34+
const tasks = []
35+
3436
if (report?.emailEnable && report.emailAddress) {
35-
await sendMail({
36-
subject: `${body.type} | ${body.subject}`,
37-
to: report.emailAddress,
38-
html: Mustache.render(reportTemplate, {
39-
type: body.type,
40-
body: body.body,
41-
deviceName,
42-
deviceUrl,
43-
}),
44-
})
37+
tasks.push(
38+
() => sendMail({
39+
subject: `${body.type} | ${body.subject}`,
40+
to: report.emailAddress!,
41+
html: Mustache.render(reportTemplate, {
42+
type: body.type,
43+
body: body.body,
44+
deviceName,
45+
deviceUrl,
46+
}),
47+
}))
4548
}
4649

4750
if (report?.webhookEnable && report.webhookUrl) {
48-
await $fetch(report.webhookUrl, {
49-
method: 'POST',
50-
body: {
51-
type: body.type,
52-
subject: body.subject,
53-
body: body.body,
54-
deviceId,
55-
projectId,
56-
},
57-
})
51+
tasks.push(
52+
() => $fetch(report.webhookUrl!, {
53+
method: 'POST',
54+
body: {
55+
type: body.type,
56+
subject: body.subject,
57+
body: body.body,
58+
deviceId,
59+
projectId,
60+
},
61+
}))
5862
}
5963

64+
await Promise.all(tasks)
65+
6066
return { status: 'ok' }
6167
})

0 commit comments

Comments
 (0)