mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-23 19:20:41 +02:00
Slight findFiles optimization
This commit is contained in:
parent
18284d8038
commit
66f444d4fb
1 changed files with 8 additions and 7 deletions
|
@ -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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue