From bfaef92db7f3f94bcee529d80d75ba0401069bcb Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Tue, 9 May 2023 11:40:55 +0200 Subject: [PATCH] use sum instead of max when sorting movies --- catalogs/addon.js | 2 +- catalogs/lib/cache.js | 1 + catalogs/lib/repository.js | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/catalogs/addon.js b/catalogs/addon.js index c23517e..5eea583 100644 --- a/catalogs/addon.js +++ b/catalogs/addon.js @@ -41,7 +41,7 @@ builder.defineCatalogHandler((args) => { staleRevalidate: STALE_REVALIDATE_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) { diff --git a/catalogs/lib/cache.js b/catalogs/lib/cache.js index 8672db3..c9e4c90 100644 --- a/catalogs/lib/cache.js +++ b/catalogs/lib/cache.js @@ -14,6 +14,7 @@ function initiateRemoteCache() { uri: MONGO_URI, options: { collection: 'torrentio_catalog_collection', + socketTimeoutMS: 120000, useNewUrlParser: true, useUnifiedTopology: false, ttl: CATALOG_TTL diff --git a/catalogs/lib/repository.js b/catalogs/lib/repository.js index 6c53850..320b7fe 100644 --- a/catalogs/lib/repository.js +++ b/catalogs/lib/repository.js @@ -12,10 +12,11 @@ async function getIds(providers, type, startDate, endDate) { : ''; const dateCondition = startDate && endDate ? `AND "uploadDate" BETWEEN '${startDate}' AND '${endDate}'` - : '' + : ''; const providersCondition = providers && providers.length ? `AND provider in (${providers.map(it => `'${it}'`).join(',')})` - : '' + : ''; + const sortCondition = type === Type.MOVIE ? 'sum(torrents.seeders)' : 'max(torrents.seeders)'; const query = `SELECT files."${idName}" FROM (SELECT torrents."infoHash", torrents.seeders FROM torrents 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" WHERE files."${idName}" IS NOT NULL ${episodeCondition} GROUP BY files."${idName}" - ORDER BY max(torrents.seeders) DESC + ORDER BY ${sortCondition} DESC LIMIT 5000` const results = await database.query(query, { type: QueryTypes.SELECT }); return results.map(result => `${result.imdbId || result.kitsuId}`);