parallelize metric fetching requests
This commit is contained in:
parent
e65922a1a0
commit
549558142d
@ -1,16 +1,19 @@
|
|||||||
import { resolver } from "blitz";
|
import { resolver } from "blitz";
|
||||||
|
|
||||||
import db from "../../../db";
|
import db from "../../../db";
|
||||||
|
|
||||||
export default resolver.pipe(async () => {
|
export default resolver.pipe(async () => {
|
||||||
const phoneNumbers = await db.phoneNumber.count();
|
const [phoneNumbers, smsExchanged, allPhoneCalls] = await Promise.all([
|
||||||
const smsExchanged = await db.message.count();
|
db.phoneNumber.count(),
|
||||||
const allPhoneCalls = await db.phoneCall.findMany();
|
db.message.count(),
|
||||||
const secondsCalled = allPhoneCalls.reduce<number>((minutes, phoneCall) => {
|
db.phoneCall.findMany(),
|
||||||
|
]);
|
||||||
|
const secondsCalled = allPhoneCalls.reduce<number>((seconds, phoneCall) => {
|
||||||
if (!phoneCall.duration) {
|
if (!phoneCall.duration) {
|
||||||
return minutes;
|
return seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
return minutes + Number.parseInt(phoneCall.duration);
|
return seconds + Number.parseInt(phoneCall.duration);
|
||||||
}, 0);
|
}, 0);
|
||||||
const minutesCalled = Math.round(secondsCalled / 60);
|
const minutesCalled = Math.round(secondsCalled / 60);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user