Changed scene year filter to range input.

This commit is contained in:
2026-11-11 23:28:53 +01:00
parent 91a5ad55cc
commit 5a9ca8710b
11 changed files with 168 additions and 82 deletions
+17 -5
View File
@@ -558,6 +558,14 @@ async function queryManticoreSql(filters, options, _reqUser) {
builder.whereIn('effective_year', filters.years);
}
if (typeof filters.yearRange?.min === 'number') {
builder.where('effective_year', '>=', filters.yearRange.min);
}
if (typeof filters.yearRange?.max === 'number') {
builder.where('effective_year', '<=', filters.yearRange.max);
}
filters.tagIds?.forEach((tagId) => {
if (filters.onlyActorTags) {
builder.where((whereBuilder) => {
@@ -776,18 +784,22 @@ export async function fetchScenes(filters, rawOptions, reqUser, context) {
console.log('options', options);
}
// an active count filter would narrow its own range to the filtered value, get the unfiltered ranges from a lightweight parallel query (~10ms vs 40-500ms for the main query with its actor and tag facets)
// an active count or year filter would narrow its own aggregation to the filtered values, get the unfiltered ranges from a lightweight parallel query (~10ms vs 40-500ms for the main query with its actor and tag facets)
// the range filters are stripped together, so with several active, each of their aggregations ignores the others
const activeCountKeys = options.aggregateActorCounts
? Object.keys(actorCountFilters).filter((key) => filters[actorCountFilters[key]])
: [];
const countsFilters = Object.fromEntries(Object.entries(filters).filter(([key]) => !Object.values(actorCountFilters).includes(key)));
const hasYearFilter = options.aggregateYears && (filters.years?.length > 0 || !!filters.yearRange);
const rangeFilterKeys = [...Object.values(actorCountFilters), 'years', 'yearRange'];
const countsFilters = Object.fromEntries(Object.entries(filters).filter(([key]) => !rangeFilterKeys.includes(key)));
const countsOptions = {
...options,
limit: 1,
page: 1,
aggregateYears: false,
aggregateYears: hasYearFilter,
aggregateActors: false,
aggregateTags: false,
aggregateChannels: false,
@@ -797,12 +809,12 @@ export async function fetchScenes(filters, rawOptions, reqUser, context) {
const [result, countsResult] = await Promise.all([
queryManticoreSql(filters, options, reqUser),
activeCountKeys.length > 0 ? queryManticoreSql(countsFilters, countsOptions, reqUser) : null,
activeCountKeys.length > 0 || hasYearFilter ? queryManticoreSql(countsFilters, countsOptions, reqUser) : null,
]);
console.timeEnd('manticore sql');
const aggYears = options.aggregateYears && result.aggregations.years.map((bucket) => ({ year: bucket.key, count: bucket.doc_count }));
const aggYears = options.aggregateYears && (hasYearFilter ? countsResult : result).aggregations.years.map((bucket) => ({ year: bucket.key, count: bucket.doc_count }));
const entityIds = options.aggregateChannels && [...(result.aggregations.channelIds || []), ...(result.aggregations.studioIds || [])];
// keyed by URL parameter, e.g. { group: [{ value: 2, count: 1234 }, ...], females: [...] }, sorted by value so the first and last bucket give the range