mirror of
https://github.com/TheBeastLT/torrentio-scraper.git
synced 2026-05-12 21:40:36 +00:00
use sum instead of max when sorting movies
This commit is contained in:
parent
0eee56aaaf
commit
bfaef92db7
3 changed files with 6 additions and 4 deletions
|
|
@ -41,7 +41,7 @@ builder.defineCatalogHandler((args) => {
|
||||||
staleRevalidate: STALE_REVALIDATE_AGE,
|
staleRevalidate: STALE_REVALIDATE_AGE,
|
||||||
staleError: STALE_ERROR_AGE
|
staleError: STALE_ERROR_AGE
|
||||||
}))
|
}))
|
||||||
.catch(error => Promise.reject(`Failed retrieving catalog ${args.id}: ${JSON.stringify(error)}`));
|
.catch(error => Promise.reject(`Failed retrieving catalog ${args.id}: ${error.message}`));
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getCursor(catalog, providers, genre, offset) {
|
async function getCursor(catalog, providers, genre, offset) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ function initiateRemoteCache() {
|
||||||
uri: MONGO_URI,
|
uri: MONGO_URI,
|
||||||
options: {
|
options: {
|
||||||
collection: 'torrentio_catalog_collection',
|
collection: 'torrentio_catalog_collection',
|
||||||
|
socketTimeoutMS: 120000,
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: false,
|
useUnifiedTopology: false,
|
||||||
ttl: CATALOG_TTL
|
ttl: CATALOG_TTL
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,11 @@ async function getIds(providers, type, startDate, endDate) {
|
||||||
: '';
|
: '';
|
||||||
const dateCondition = startDate && endDate
|
const dateCondition = startDate && endDate
|
||||||
? `AND "uploadDate" BETWEEN '${startDate}' AND '${endDate}'`
|
? `AND "uploadDate" BETWEEN '${startDate}' AND '${endDate}'`
|
||||||
: ''
|
: '';
|
||||||
const providersCondition = providers && providers.length
|
const providersCondition = providers && providers.length
|
||||||
? `AND provider in (${providers.map(it => `'${it}'`).join(',')})`
|
? `AND provider in (${providers.map(it => `'${it}'`).join(',')})`
|
||||||
: ''
|
: '';
|
||||||
|
const sortCondition = type === Type.MOVIE ? 'sum(torrents.seeders)' : 'max(torrents.seeders)';
|
||||||
const query = `SELECT files."${idName}"
|
const query = `SELECT files."${idName}"
|
||||||
FROM (SELECT torrents."infoHash", torrents.seeders FROM torrents
|
FROM (SELECT torrents."infoHash", torrents.seeders FROM torrents
|
||||||
WHERE seeders > 0 AND type = '${type}' ${providersCondition} ${dateCondition}
|
WHERE seeders > 0 AND type = '${type}' ${providersCondition} ${dateCondition}
|
||||||
|
|
@ -23,7 +24,7 @@ async function getIds(providers, type, startDate, endDate) {
|
||||||
JOIN files ON torrents."infoHash" = files."infoHash"
|
JOIN files ON torrents."infoHash" = files."infoHash"
|
||||||
WHERE files."${idName}" IS NOT NULL ${episodeCondition}
|
WHERE files."${idName}" IS NOT NULL ${episodeCondition}
|
||||||
GROUP BY files."${idName}"
|
GROUP BY files."${idName}"
|
||||||
ORDER BY max(torrents.seeders) DESC
|
ORDER BY ${sortCondition} DESC
|
||||||
LIMIT 5000`
|
LIMIT 5000`
|
||||||
const results = await database.query(query, { type: QueryTypes.SELECT });
|
const results = await database.query(query, { type: QueryTypes.SELECT });
|
||||||
return results.map(result => `${result.imdbId || result.kitsuId}`);
|
return results.map(result => `${result.imdbId || result.kitsuId}`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue