我有一个上传文件的数据库,每个文件可以有4个阶段之一;接收、转换、完成和失败。需要对每个阶段进行计数。日期存储在ms的“receivedat”列中。这是我的代码。这是可行的,但需要很长时间才能把所有的信息都弄出来。
const dates = await Job.aggregate("recievedAt", "DISTINCT", { plain: false });
const dates_sorted = dates.sort((a, b) => a - b);
const rev_date = dates_sorted.reverse();
let day;
const summery_by_date = [];
try {
await Promise.all(
rev_date.map(async (date) => {
const string_d = new Date(Number(date.DISTINCT)).toDateString();
if (!(day === string_d)) {
day = string_d;
const d_num = new Date(Number(date.DISTINCT));
const date_midnight = d_num.toISOString().split("T")[0];
const beaging_date = Number(new Date(date_midnight).getTime());
const end_date = Number(beaging_date + 86400000);
const total = await Job.count({
where: {
recievedAt: {
[Op.between]: [beaging_date, end_date],
},
},
});
const failed = await Job.count({
where: {
[Op.and]: [
{
recievedAt: {
[Op.between]: [beaging_date, end_date],
},
},
{ stage: "failed" },
],
},
});
const converting = await Job.count({
where: {
[Op.and]: [
{
recievedAt: {
[Op.between]: [beaging_date, end_date],
},
},
{ stage: "converting" },
],
},
});
const recieved = await Job.count({
where: {
[Op.and]: [
{
recievedAt: {
[Op.between]: [beaging_date, end_date],
},
},
{ stage: "recieved" },
],
},
});
const done = await Job.count({
where: {
[Op.and]: [
{
recievedAt: {
[Op.between]: [beaging_date, end_date],
},
},
{ stage: "done" },
],
},
});
summery_by_date.push({
date: beaging_date,
total: total,
failed: failed,
converting: converting,
recieved: recieved,
done: done,
});`
提前谢谢
暂无答案!
目前还没有任何答案,快来回答吧!