From 56dfc245e6cfeb322f48c16418545708bd487740 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Sun, 30 Jul 2017 11:24:12 -0700 Subject: [PATCH] revised trending to look at past 3 days --- controllers/statsController.js | 6 +++--- routes/home-routes.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/statsController.js b/controllers/statsController.js index e9593c4b..ee50f970 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -144,10 +144,11 @@ module.exports = { }, getTrendingClaims (startDate) { logger.debug('retrieving trending requests'); - const deferred = new Promise((resolve, reject) => { + const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' '); + return new Promise((resolve, reject) => { // get the raw requests data db.sequelize - .query('SELECT COUNT(*), File.* FROM Request LEFT JOIN File ON Request.FileId = File.id WHERE FileId IS NOT NULL AND nsfw != 1 AND trendingEligible = 1 GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;', { type: db.sequelize.QueryTypes.SELECT }) + .query(`SELECT COUNT(*), File.* FROM Request LEFT JOIN File ON Request.FileId = File.id WHERE FileId IS NOT NULL AND nsfw != 1 AND trendingEligible = 1 AND Request.createdAt > "${dateTime}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT }) .then(results => { resolve(results); }) @@ -156,6 +157,5 @@ module.exports = { reject(error); }); }); - return deferred; }, }; diff --git a/routes/home-routes.js b/routes/home-routes.js index 8089f947..658e4711 100644 --- a/routes/home-routes.js +++ b/routes/home-routes.js @@ -6,7 +6,7 @@ module.exports = app => { app.get('/', ({ headers, ip, originalUrl }, res) => { // get yesterday's date const startDate = new Date(); - startDate.setDate(startDate.getDate() - 1); + startDate.setDate(startDate.getDate() - 3); // send response getTrendingClaims(startDate) .then(result => {