-
-
Notifications
You must be signed in to change notification settings - Fork 891
feat(discover): add exclusionary filters with per-dimension include/exclude toggles #3166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheReaperJay
wants to merge
6
commits into
seerr-team:develop
Choose a base branch
from
TheReaperJay:feat-exclusionary-filters
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,506
−364
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
01fd711
feat(discover): add exclusionary filters with per-dimension include/e…
TheReaperJay 725abcb
refactor(discover): centralize dimension registry and derive types fr…
TheReaperJay 55d6b7d
fix(discover): keep mixed exclusion filters stable and honour languag…
TheReaperJay e4087bf
chore(i18n): extract translation keys for exclusionary discover filters
TheReaperJay af4152c
docs: document include/exclude discover filter toggles
TheReaperJay cbb9167
fixup(discover): address review feedback on typing, robustness and sync
TheReaperJay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type TheMovieDb from '@server/api/themoviedb'; | ||
|
|
||
| /** | ||
| * Returns all ISO 3166-1 country codes. Reuses the existing `getRegions()` | ||
| * method which is already cached for 24 hours via nodeCache. | ||
| */ | ||
| export async function getAllCountryCodes(tmdb: TheMovieDb): Promise<string[]> { | ||
| const regions = await tmdb.getRegions(); | ||
| return regions.map((r) => r.iso_3166_1).filter(Boolean); | ||
| } | ||
|
|
||
| /** | ||
| * Given the full set of codes and a subset to exclude, returns a pipe-joined | ||
| * string of everything EXCEPT the excluded codes. TMDB has no way to exclude | ||
| * an origin country directly, so we instead ask it to include the complement. | ||
| */ | ||
| export function buildComplement(allCodes: string[], exclude: string[]): string { | ||
| const excludeSet = new Set(exclude); | ||
| const result = allCodes.filter((c) => !excludeSet.has(c)).join('|'); | ||
| if (result.length > 7500) { | ||
| throw new Error('Complement string exceeds safe URL length'); | ||
| } | ||
| return result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { PAGE_SIZE } from '@server/discover/planBuilder'; | ||
| import { applyPostFilter } from '@server/discover/postFilter'; | ||
| import type { HonestPage, ListResult, PostFilterSpec } from './types'; | ||
|
|
||
| interface TmdbPage<T> { | ||
| results: T[]; | ||
| total_pages: number; | ||
| total_results: number; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch TMDB discover pages and return a result whose pagination tells the | ||
| * truth about what the user will actually see. | ||
| * | ||
| * When no post-filter is active (common case), exactly one TMDB call is made | ||
| * and the response is honest. | ||
| * | ||
| * When a post-filter IS active (language exclude, TV country exclude), TMDB's | ||
| * total_results is a pre-filter count. To fill the requested page with real | ||
| * results we may need to over-fetch — up to `maxOverFetch` extra pages. This | ||
| * is a bounded trade of correctness for calls. | ||
| */ | ||
| export async function fillPage<T extends ListResult>( | ||
| fetch: (page: number) => Promise<TmdbPage<T>>, | ||
| postFilter: PostFilterSpec, | ||
| requestedPage: number, | ||
| maxOverFetch = 3 | ||
| ): Promise<HonestPage<T>> { | ||
| const hasPostFilter = | ||
| !!postFilter.excludeLanguages?.length || | ||
| !!postFilter.excludeCountries?.length; | ||
|
|
||
| if (!hasPostFilter) { | ||
| const res = await fetch(requestedPage); | ||
| return { | ||
| page: requestedPage, | ||
| totalPages: res.total_pages, | ||
| totalResults: res.total_results, | ||
| results: res.results, | ||
| paginationIsEstimate: false, | ||
| }; | ||
| } | ||
|
|
||
| const collected: T[] = []; | ||
| let tmdbPage = requestedPage; | ||
| let extra = 0; | ||
| let lastTotalPages = 0; | ||
| let lastTotalResults = 0; | ||
| let anyDropped = false; | ||
|
|
||
| while (collected.length < PAGE_SIZE) { | ||
| const res = await fetch(tmdbPage); | ||
| lastTotalPages = res.total_pages; | ||
| lastTotalResults = res.total_results; | ||
|
|
||
| const { filtered, dropped } = applyPostFilter(res.results, postFilter); | ||
| if (dropped > 0) anyDropped = true; | ||
| collected.push(...filtered); | ||
|
|
||
| if (extra >= maxOverFetch) break; | ||
| if (tmdbPage >= res.total_pages) break; | ||
| tmdbPage++; | ||
| extra++; | ||
| } | ||
|
|
||
| return { | ||
| page: requestedPage, | ||
| totalPages: lastTotalPages, | ||
| totalResults: lastTotalResults, | ||
| results: collected.slice(0, PAGE_SIZE), | ||
| paginationIsEstimate: anyDropped, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.