[scraper] reduces number of calls to 1337x

This commit is contained in:
TheBeastLT
2020-10-02 12:49:45 +02:00
parent 42714d19a9
commit 5426707dd9
5 changed files with 18 additions and 17 deletions

View File

@@ -163,13 +163,10 @@ function getProvider(provider) {
}
function getTorrent(torrent) {
return Torrent.findByPk(torrent.infoHash)
.then((result) => {
if (!result) {
throw new Error(`torrent not found: ${torrent.infoHash}`);
}
return result;
})
const where = torrent.infoHash
? { infoHash: torrent.infoHash }
: { provider: torrent.provider, torrentId: torrent.torrentId }
return Torrent.findOne({ where: where });
}
function getTorrentsBasedOnTitle(titleQuery, type) {
@@ -212,10 +209,13 @@ function createTorrent(torrent) {
.then(() => createSubtitles(torrent.infoHash, torrent.subtitles));
}
function setTorrentSeeders(infoHash, seeders) {
function setTorrentSeeders(torrent, seeders) {
const where = torrent.infoHash
? { infoHash: torrent.infoHash }
: { provider: torrent.provider, torrentId: torrent.torrentId }
return Torrent.update(
{ seeders: seeders },
{ where: { infoHash: infoHash } }
{ where: where }
);
}

View File

@@ -151,11 +151,11 @@ async function createTorrentContents(torrent) {
}
async function updateTorrentSeeders(torrent) {
if (!torrent.infoHash || !Number.isInteger(torrent.seeders)) {
if (!(torrent.infoHash || (torrent.provider && torrent.torrentId)) || !Number.isInteger(torrent.seeders)) {
return;
}
return repository.setTorrentSeeders(torrent.infoHash, torrent.seeders)
return repository.setTorrentSeeders(torrent, torrent.seeders)
.catch(error => {
console.warn('Failed updating seeders:', error);
return undefined;