Slight findFiles optimization
This commit is contained in:
@@ -483,7 +483,7 @@ module.exports = class FileEntry {
|
|||||||
sqlOrderBy = `ORDER BY avg_rating ${sqlOrderDir}`;
|
sqlOrderBy = `ORDER BY avg_rating ${sqlOrderDir}`;
|
||||||
} else {
|
} else {
|
||||||
sql =
|
sql =
|
||||||
`SELECT DISTINCT f.file_id, f.${filter.sort}
|
`SELECT DISTINCT f.file_id
|
||||||
FROM file f`;
|
FROM file f`;
|
||||||
|
|
||||||
sqlOrderBy = getOrderByWithCast(`f.${filter.sort}`) + ' ' + sqlOrderDir;
|
sqlOrderBy = getOrderByWithCast(`f.${filter.sort}`) + ' ' + sqlOrderDir;
|
||||||
@@ -579,13 +579,14 @@ module.exports = class FileEntry {
|
|||||||
|
|
||||||
sql += ';';
|
sql += ';';
|
||||||
|
|
||||||
const matchingFileIds = [];
|
fileDb.all(sql, (err, rows) => {
|
||||||
fileDb.each(sql, (err, fileId) => {
|
if(err) {
|
||||||
if(fileId) {
|
return cb(err);
|
||||||
matchingFileIds.push(fileId.file_id);
|
|
||||||
}
|
}
|
||||||
}, err => {
|
if(!rows || 0 === rows.length) {
|
||||||
return cb(err, matchingFileIds);
|
return cb(null, []); // no matches
|
||||||
|
}
|
||||||
|
return cb(null, rows.map(r => r.file_id));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user