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