Skip to content

Commit

Permalink
Fix search limit config item (cross-seed#479)
Browse files Browse the repository at this point in the history
The SQL query for the filterTimestamps function was malformed and would
return the same (too high, low) timestamp every time, since it didn't
filter for torrent name, and because max and min were reversed. It would
never filter any torrent unless every single torrent had an extant entry
in the db for every indexer.

Fixes cross-seed#453
  • Loading branch information
mmgoodnow authored Sep 12, 2023
2 parents a48f118 + ed08bfc commit b0ac598
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/preFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ export async function filterTimestamps(searchee: Searchee): Promise<boolean> {
"timestamp.indexer_id": "indexer.id",
"timestamp.searchee_id": "searchee.id",
})
.where("searchee.name",
searchee.name
)
.whereIn(
"indexer.id",
enabledIndexers.map((i) => i.id)
)
.max({
first_searched_all: db.raw(
.min({
first_searched_any: db.raw(
"coalesce(timestamp.first_searched, 9223372036854775807)"
),
})
Expand All @@ -84,7 +87,7 @@ export async function filterTimestamps(searchee: Searchee): Promise<boolean> {
})
.first();

const { first_searched_all, last_searched_all } = timestampDataSql;
const { first_searched_any, last_searched_all } = timestampDataSql;
function logReason(reason) {
logger.verbose({
label: Label.PREFILTER,
Expand All @@ -94,12 +97,12 @@ export async function filterTimestamps(searchee: Searchee): Promise<boolean> {

if (
typeof excludeOlder === "number" &&
first_searched_all &&
first_searched_all < nMsAgo(excludeOlder)
first_searched_any &&
first_searched_any < nMsAgo(excludeOlder)
) {
logReason(
`its first search timestamp ${humanReadable(
first_searched_all
first_searched_any
)} is older than ${ms(excludeOlder, { long: true })} ago`
);
return false;
Expand Down

0 comments on commit b0ac598

Please sign in to comment.