switched trending images controller function to sql query

This commit is contained in:
bill bittner 2017-07-12 23:37:38 -07:00
parent 45ce1c44c6
commit 02d909a738
2 changed files with 5 additions and 54 deletions

View file

@ -9,7 +9,7 @@
}, },
"Database": { "Database": {
"MySqlConnectionUri": "none", "MySqlConnectionUri": "none",
"DownloadDirectory": "C:\\Users\\Bones\\Downloads\\lbry\\" "DownloadDirectory": "/home/lbry/Downloads/"
}, },
"Logging": { "Logging": {
"LogLevel": "silly" "LogLevel": "silly"

View file

@ -148,59 +148,10 @@ module.exports = {
logger.debug('retrieving trending requests'); logger.debug('retrieving trending requests');
const deferred = new Promise((resolve, reject) => { const deferred = new Promise((resolve, reject) => {
// get the raw requests data // get the raw requests data
db.Request db.sequelize
.findAll({ .query('SELECT COUNT(*), file.* FROM request LEFT JOIN file ON request.FileId = file.id WHERE FileId != "null" AND nsfw != 1 GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;', { type: db.sequelize.QueryTypes.SELECT })
where: { .then(results => {
createdAt: { resolve(results);
gt: startDate,
},
FileId: {
not: null,
},
},
include: [db.File],
})
.then(data => {
if (data) {
logger.debug(data[0].File.name);
}
// let resultHashTable = {};
// let sortableArray = [];
// let sortedArray;
// // summarise the data
// for (let i = 0; i < data.length; i++) {
// let key = data[i].fileId;
// if (resultHashTable[key] === undefined) {
// resultHashTable[key] = {
// count : 0,
// details: {
// name : data[i].name,
// claimId : data[i].claimId,
// fileName: data[i].fileName,
// fileType: data[i].fileType,
// nsfw : data[i].nsfw,
// },
// };
// } else {
// resultHashTable[key]['count'] += 1;
// }
// }
// for (let objKey in resultHashTable) {
// if (resultHashTable.hasOwnProperty(objKey)) {
// sortableArray.push([
// resultHashTable[objKey]['count'],
// resultHashTable[objKey]['details'],
// ]);
// }
// }
// sortableArray.sort((a, b) => {
// return b[0] - a[0];
// });
// sortedArray = sortableArray.map((a) => {
// return a[1];
// });
// // return results
resolve();
}) })
.catch(error => { .catch(error => {
logger.error('sequelize error', error); logger.error('sequelize error', error);