Fixed actor and channel aggregation duplicates.

This commit is contained in:
2026-03-05 16:34:41 +01:00
parent dd522c1fb1
commit 185984bf0c

View File

@@ -564,15 +564,15 @@ async function queryManticoreSql(filters, options, _reqUser) {
.offset((options.page - 1) * options.limit), .offset((options.page - 1) * options.limit),
// option threads=1 fixes actors, but drastically slows down performance, wait for fix // option threads=1 fixes actors, but drastically slows down performance, wait for fix
yearsFacet: options.aggregateYears ? knex.raw('facet effective_year as years order by effective_year desc limit ?', [aggSize]) : null, yearsFacet: options.aggregateYears ? knex.raw('facet effective_year as years order by effective_year desc limit ?', [aggSize]) : null,
actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null, actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids distinct id order by count(distinct id) desc limit ?', [aggSize]) : null,
// don't facet tags associated to other actors, actor ID 0 means global // don't facet tags associated to other actors, actor ID 0 means global
tagsFacet: options.aggregateTags // eslint-disable-line no-nested-ternary tagsFacet: options.aggregateTags // eslint-disable-line no-nested-ternary
? (filters.stashId // we can't join the tags table as well as the stashes table ? (filters.stashId // we can't join the tags table as well as the stashes table
? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize]) ? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize])
: knex.raw(`facet IF(IN(scenes_tags.actor_id, ${[0, ...filters?.actorIds || []]}), scenes_tags.tag_id, 0) as tags_facet distinct id order by count(distinct id) desc limit ?`, [aggSize])) : knex.raw(`facet IF(IN(scenes_tags.actor_id, ${[0, ...filters?.actorIds || []]}), scenes_tags.tag_id, 0) as tags_facet distinct id order by count(distinct id) desc limit ?`, [aggSize]))
: null, : null,
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id order by count(*) desc limit ?', [aggSize]) : null, channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id distinct id order by count(distinct id) desc limit ?', [aggSize]) : null,
studiosFacet: options.aggregateChannels ? knex.raw('facet scenes.studio_id order by count(*) desc limit ?', [aggSize]) : null, studiosFacet: options.aggregateChannels ? knex.raw('facet scenes.studio_id distinct id order by count(distinct id) desc limit ?', [aggSize]) : null,
maxMatches: config.database.manticore.maxMatches, maxMatches: config.database.manticore.maxMatches,
maxQueryTime: config.database.manticore.maxQueryTime, maxQueryTime: config.database.manticore.maxQueryTime,
}).toString(); }).toString();
@@ -598,8 +598,8 @@ async function queryManticoreSql(filters, options, _reqUser) {
|| []; || [];
const actorIds = results const actorIds = results
.find((result) => (result.columns[0].actor_ids || result.columns[0]['scenes.actor_ids']) && result.columns[1]['count(*)']) .find((result) => (result.columns[0].actor_ids || result.columns[0]['scenes.actor_ids']) && result.columns[1]['count(distinct id)'])
?.data.map((row) => ({ key: row.actor_ids || row['scenes.actor_ids'], doc_count: row['count(*)'] })) ?.data.map((row) => ({ key: row.actor_ids || row['scenes.actor_ids'], doc_count: row['count(distinct id)'] }))
|| []; || [];
const tagIds = results const tagIds = results
@@ -608,14 +608,14 @@ async function queryManticoreSql(filters, options, _reqUser) {
|| []; || [];
const channelIds = results const channelIds = results
.find((result) => (result.columns[0].channel_id || result.columns[0]['scenes.channel_id']) && result.columns[1]['count(*)']) .find((result) => (result.columns[0].channel_id || result.columns[0]['scenes.channel_id']) && result.columns[1]['count(distinct id)'])
?.data.map((row) => ({ key: row.channel_id || row['scenes.channel_id'], doc_count: row['count(*)'] })) ?.data.map((row) => ({ key: row.channel_id || row['scenes.channel_id'], doc_count: row['count(distinct id)'] }))
|| []; || [];
const studioIds = results const studioIds = results
.find((result) => (result.columns[0].studio_id || result.columns[0]['scenes.studio_id']) && result.columns[1]['count(*)']) .find((result) => (result.columns[0].studio_id || result.columns[0]['scenes.studio_id']) && result.columns[1]['count(distinct id)'])
?.data ?.data
.map((row) => ({ key: row.studio_id || row['scenes.studio_id'], doc_count: row['count(*)'] })) .map((row) => ({ key: row.studio_id || row['scenes.studio_id'], doc_count: row['count(distinct id)'] }))
.filter((row) => !!row.key) .filter((row) => !!row.key)
|| []; || [];