Skip to content

Commit

Permalink
perform assessments serially to avoid artificially long snatches
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Dec 29, 2023
1 parent a34e3e9 commit 31f9b0c
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,27 @@ interface FoundOnOtherSites {
matches: number;
}

async function assessCandidates(
candidates: Candidate[],
searchee: Searchee,
hashesToExclude: string[]
) {
const assessments = [];
for (const result of candidates) {
const assessment = await assessCandidate(
result,
searchee,
hashesToExclude
);
assessments.push({ assessment, tracker: result.tracker });
}
return assessments;
}

async function findOnOtherSites(
searchee: Searchee,
hashesToExclude: string[]
): Promise<FoundOnOtherSites> {
const assessEach = async (
result: Candidate
): Promise<AssessmentWithTracker> => ({
assessment: await assessCandidate(result, searchee, hashesToExclude),
tracker: result.tracker,
});

// make sure searchee is in database
await db("searchee")
.insert({ name: searchee.name })
Expand All @@ -94,11 +104,13 @@ async function findOnOtherSites(
}))
);

const assessed = await Promise.all<AssessmentWithTracker>(
results.map(assessEach)
const assessments = await assessCandidates(
results,
searchee,
hashesToExclude
);

const { rateLimited, notRateLimited } = assessed.reduce(
const { rateLimited, notRateLimited } = assessments.reduce(
(acc, cur, idx) => {
const candidate = results[idx];
if (cur.assessment.decision === Decision.RATE_LIMITED) {
Expand All @@ -113,7 +125,7 @@ async function findOnOtherSites(
}
);

const matches = assessed.filter(
const matches = assessments.filter(
(e) =>
e.assessment.decision === Decision.MATCH ||
e.assessment.decision === Decision.MATCH_SIZE_ONLY
Expand Down

0 comments on commit 31f9b0c

Please sign in to comment.