From 66f444d4fb4b9d9b462204f49b033789414075d6 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 17 Mar 2018 13:48:11 -0600 Subject: [PATCH] Slight findFiles optimization --- core/file_entry.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/file_entry.js b/core/file_entry.js index 2ec03c17..169bbb74 100644 --- a/core/file_entry.js +++ b/core/file_entry.js @@ -483,7 +483,7 @@ module.exports = class FileEntry { sqlOrderBy = `ORDER BY avg_rating ${sqlOrderDir}`; } else { sql = - `SELECT DISTINCT f.file_id, f.${filter.sort} + `SELECT DISTINCT f.file_id FROM file f`; sqlOrderBy = getOrderByWithCast(`f.${filter.sort}`) + ' ' + sqlOrderDir; @@ -579,13 +579,14 @@ module.exports = class FileEntry { sql += ';'; - const matchingFileIds = []; - fileDb.each(sql, (err, fileId) => { - if(fileId) { - matchingFileIds.push(fileId.file_id); + fileDb.all(sql, (err, rows) => { + if(err) { + return cb(err); } - }, err => { - return cb(err, matchingFileIds); + if(!rows || 0 === rows.length) { + return cb(null, []); // no matches + } + return cb(null, rows.map(r => r.file_id)); }); }