[scraper] simplify update seeders query

This commit is contained in:
TheBeastLT
2020-04-28 09:29:40 +02:00
parent 95c2893523
commit 529f5ba76c
4 changed files with 13 additions and 13 deletions

View File

@@ -130,6 +130,13 @@ function createTorrent(torrent) {
return Torrent.upsert(torrent);
}
function setTorrentSeeders(infoHash, seeders) {
return Torrent.update(
{ seeders: seeders },
{ where: { infoHash: infoHash } }
);
}
function createFile(file) {
return File.upsert(file);
}
@@ -164,6 +171,7 @@ module.exports = {
connect,
getProvider,
createTorrent,
setTorrentSeeders,
getTorrent,
getTorrentsBasedOnTitle,
getUpdateSeedersTorrents,

View File

@@ -84,19 +84,11 @@ async function getStoredTorrentEntry(torrent) {
}
async function updateTorrentSeeders(torrent) {
if (torrent.seeders === undefined) {
if (!torrent.infoHash || !Number.isInteger(torrent.seeders)) {
return;
}
return repository.getTorrent(torrent)
.catch(() => undefined)
.then(stored => {
if (stored) {
stored.seeders = torrent.seeders;
stored.changed('updatedAt', true);
return stored.save()
}
})
return repository.setTorrentSeeders(torrent.infoHash, torrent.seeders)
.catch(error => {
console.warn('Failed updating seeders:', error);
return undefined;