Skip to content

Commit

Permalink
Add --search-limit config flag to the search command
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricionaweb committed Jun 5, 2023
1 parent 5f9af42 commit f7c6dc6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ createCommandWithSharedOptions("search", "Search for cross-seeds")
"torrent files separated by spaces"
).hideHelp()
)
.addOption(
new Option(
"--search-limit <number>",
"set the limit of searches for the running"
)
)
.action(async (options) => {
try {
const runtimeConfig = processOptions(options);
Expand Down
13 changes: 11 additions & 2 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function checkNewCandidateMatch(
}

async function findSearchableTorrents() {
const { torrents, dataDirs, torrentDir } = getRuntimeConfig();
const { torrents, dataDirs, torrentDir, searchLimit } = getRuntimeConfig();
let allSearchees: Searchee[] = [];
if (Array.isArray(torrents)) {
const searcheeResults = await Promise.all(
Expand All @@ -255,7 +255,7 @@ async function findSearchableTorrents() {
}

const hashesToExclude = allSearchees.map((t) => t.infoHash).filter(Boolean);
const filteredTorrents = await filterAsync(
let filteredTorrents = await filterAsync(
filterDupes(allSearchees).filter(filterByContent),
filterTimestamps
);
Expand All @@ -265,6 +265,15 @@ async function findSearchableTorrents() {
message: `Found ${allSearchees.length} torrents, ${filteredTorrents.length} suitable to search for matches`,
});

if (searchLimit && filteredTorrents.length > searchLimit) {
logger.info({
label: Label.SEARCH,
message: `Limited to ${searchLimit} searches`,
});

filteredTorrents = filteredTorrents.slice(0, searchLimit);
}

return { samples: filteredTorrents, hashesToExclude };
}

Expand Down
2 changes: 2 additions & 0 deletions src/runtimeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Action, LinkType, MatchMode } from "./constants.js";

export interface RuntimeConfig {
offset: number;
delay: number;
Expand Down Expand Up @@ -30,6 +31,7 @@ export interface RuntimeConfig {
rssCadence: number;
snatchTimeout: number;
searchTimeout: number;
searchLimit: number;
}

let runtimeConfig: RuntimeConfig;
Expand Down

0 comments on commit f7c6dc6

Please sign in to comment.