150 resovle channels updates #156

Merged
bones7242 merged 11 commits from 150-resovle-channels-updates into master 2017-09-11 00:27:25 +02:00
2 changed files with 13 additions and 5 deletions
Showing only changes of commit 4d94acee77 - Show all commits

View file

@ -147,7 +147,7 @@ module.exports = {
const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' '); const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' ');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// get the raw requests data // 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 AND Request.createdAt > "${dateTime}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT }) db.getTrendingClaims(dateTime)
.then(results => { .then(results => {
resolve(results); resolve(results);
}) })
@ -157,11 +157,11 @@ module.exports = {
}); });
}); });
}, },
getRecentClaims (startDate) { getRecentClaims () {
logger.debug('retrieving most recent claims'); logger.debug('retrieving most recent claims');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// get the raw requests data // get the raw requests data
db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT }) db.getRecentClaims()
.then(results => { .then(results => {
resolve(results); resolve(results);
}) })

View file

@ -43,6 +43,9 @@ Object.keys(db).forEach(modelName => {
} }
}); });
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db['upsert'] = (Model, values, condition, tableName) => { db['upsert'] = (Model, values, condition, tableName) => {
return Model return Model
.findOne({ where: condition }) .findOne({ where: condition })
@ -59,7 +62,12 @@ db['upsert'] = (Model, values, condition, tableName) => {
}); });
}; };
db.sequelize = sequelize; db['getTrendingClaims'] = (startDate) => {
db.Sequelize = Sequelize; return 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 AND Request.createdAt > "${startDate}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
};
db['getRecentClaims'] = () => {
return db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
};
module.exports = db; module.exports = db;