From 89cd31ed2822a1bbe7b1be50b3e842bb2111d064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 21 Aug 2019 01:30:00 -0400 Subject: [PATCH] feat: faster initial stat loading --- src/controllers/admin/dashboard.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 43dbb8b4b5..a5fb7a6698 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -137,11 +137,11 @@ async function getStatsForSet(set, field) { const now = Date.now(); const results = await utils.promiseParallel({ - yesterday: db.sortedSetCount(set, now - (terms.day * 2), now - terms.day), + yesterday: db.sortedSetCount(set, now - (terms.day * 2), '+inf'), today: db.sortedSetCount(set, now - terms.day, '+inf'), - lastweek: db.sortedSetCount(set, now - (terms.week * 2), now - terms.week), + lastweek: db.sortedSetCount(set, now - (terms.week * 2), '+inf'), thisweek: db.sortedSetCount(set, now - terms.week, '+inf'), - lastmonth: db.sortedSetCount(set, now - (terms.month * 2), now - terms.month), + lastmonth: db.sortedSetCount(set, now - (terms.month * 2), '+inf'), thismonth: db.sortedSetCount(set, now - terms.month, '+inf'), alltime: getGlobalField(field), }); @@ -159,12 +159,15 @@ async function getStatsForSet(set, field) { const percent = last ? (now - last) / last * 100 : 0; return percent.toFixed(1); } + results.yesterday -= results.today; results.dayIncrease = increasePercent(results.yesterday, results.today); results.dayTextClass = textClass(results.dayIncrease); + results.lastweek -= results.thisweek; results.weekIncrease = increasePercent(results.lastweek, results.thisweek); results.weekTextClass = textClass(results.weekIncrease); + results.lastmonth -= results.thismonth; results.monthIncrease = increasePercent(results.lastmonth, results.thismonth); results.monthTextClass = textClass(results.monthIncrease);