From 7ba06fa4d994e07f81b317c54417ea55a9b876eb Mon Sep 17 00:00:00 2001 From: Colin Hebert Date: Fri, 3 Nov 2023 12:41:51 +1100 Subject: [PATCH] findOnOtherSites only completes if the torrent is complete (#523) This changes the logic of `findOnOtherSites` to ensure that the search is considered as "complete" only when the torrent itself is complete. This avoids issues where the torrent is not complete yet the search is marked as successful therefore there won't be a search done for the torrent once it has completed. --- src/pipeline.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index 8614a8702..d1127e978 100755 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -113,6 +113,17 @@ async function findOnOtherSites( } ); + const matches = assessed.filter( + (e) => + e.assessment.decision === Decision.MATCH || + e.assessment.decision === Decision.MATCH_SIZE_ONLY + ); + const actionResults = await performActions(searchee, matches); + if (actionResults.includes(InjectionResult.TORRENT_NOT_COMPLETE)) { + // If the torrent is not complete, "cancel the search" + return { matches: 0, searchedIndexers: 0 }; + } + await updateSearchTimestamps(searchee.name, Array.from(notRateLimited)); await updateIndexerStatus( @@ -121,21 +132,13 @@ async function findOnOtherSites( Array.from(rateLimited) ); - const matches = assessed.filter( - (e) => - e.assessment.decision === Decision.MATCH || - e.assessment.decision === Decision.MATCH_SIZE_ONLY + const zipped: [ResultAssessment, string, ActionResult][] = zip( + matches.map((m) => m.assessment), + matches.map((m) => m.tracker), + actionResults ); - const actionResults = await performActions(searchee, matches); + sendResultsNotification(searchee, zipped, Label.SEARCH); - if (!actionResults.includes(InjectionResult.TORRENT_NOT_COMPLETE)) { - const zipped: [ResultAssessment, string, ActionResult][] = zip( - matches.map((m) => m.assessment), - matches.map((m) => m.tracker), - actionResults - ); - sendResultsNotification(searchee, zipped, Label.SEARCH); - } return { matches: matches.length, searchedIndexers: response.length }; }