Added studios to filters and scene page.

This commit is contained in:
2024-09-03 05:56:14 +02:00
parent c3362e614e
commit 60c7e2a876
12 changed files with 108 additions and 19 deletions

6
src/entities-prefixes.js Normal file
View File

@@ -0,0 +1,6 @@
export default {
channel: '',
network: '_',
studio: '*',
info: '@',
};

View File

@@ -1,16 +1,10 @@
import knex from './knex.js';
import redis from './redis.js';
import initLogger from './logger.js';
import entityPrefixes from './entities-prefixes.js';
const logger = initLogger();
const entityPrefixes = {
channel: '',
network: '_',
studio: '*',
info: '@',
};
export function curateEntity(entity, context) {
if (!entity) {
return null;

View File

@@ -79,6 +79,13 @@ function curateScene(rawScene, assets) {
type: assets.channel.network_type,
hasLogo: assets.channel.network_has_logo,
} : null,
studio: assets.studio ? {
id: assets.studio.id,
slug: assets.studio.slug,
name: assets.studio.name,
type: assets.studio.type,
hasLogo: assets.studio.has_logo,
} : null,
affiliate: assets.channel.affiliate ? {
id: assets.channel.affiliate.id,
url: assets.channel.affiliate.url,
@@ -132,6 +139,7 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
const {
scenes,
channels,
studios,
actors,
directors,
tags,
@@ -161,6 +169,10 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
.leftJoin('entities as networks', 'networks.id', 'channels.parent_id')
.leftJoin('affiliates', knex.raw('affiliates.entity_id in (channels.id, networks.id)'))
.groupBy('channels.id', 'networks.id', 'affiliates.id'),
studios: knex('releases')
.whereIn('releases.id', sceneIds)
.leftJoin('entities as studios', 'studios.id', 'releases.studio_id'),
// .leftJoin('entities as networks', 'networks.id', 'studios.parent_id'),
actors: knex('releases_actors')
.select(
'actors.*',
@@ -265,6 +277,7 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
}
const sceneChannel = channels.find((entity) => entity.id === scene.entity_id);
const sceneStudio = studios.find((entity) => entity.id === scene.studio_id);
const sceneActors = actors.filter((actor) => actor.release_id === sceneId);
const sceneDirectors = directors.filter((director) => director.release_id === sceneId);
const sceneTags = tags.filter((tag) => tag.release_id === sceneId);
@@ -280,6 +293,7 @@ export async function fetchScenesById(sceneIds, { reqUser, ...context } = {}) {
return curateScene(scene, {
channel: sceneChannel,
studio: sceneStudio,
actors: sceneActors,
directors: sceneDirectors,
tags: sceneTags,
@@ -339,7 +353,8 @@ async function queryManticoreSql(filters, options, _reqUser) {
:yearsFacet:
:actorsFacet:
:tagsFacet:
:channelsFacet:;
:channelsFacet:
:studiosFacet:;
show meta;
`, {
query: knexManticore(filters.stashId ? 'scenes_stashed' : 'scenes')
@@ -470,6 +485,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null,
tagsFacet: options.aggregateTags ? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize]) : null,
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id order by count(*) desc limit ?', [aggSize]) : null,
studiosFacet: options.aggregateChannels ? knex.raw('facet scenes.studio_id order by count(*) desc limit ?', [aggSize]) : null,
maxMatches: config.database.manticore.maxMatches,
maxQueryTime: config.database.manticore.maxQueryTime,
}).toString();
@@ -507,6 +523,13 @@ async function queryManticoreSql(filters, options, _reqUser) {
?.data.map((row) => ({ key: row.channel_id || row['scenes.channel_id'], doc_count: row['count(*)'] }))
|| [];
const studioIds = results
.find((result) => (result.columns[0].studio_id || result.columns[0]['scenes.studio_id']) && result.columns[1]['count(*)'])
?.data
.map((row) => ({ key: row.studio_id || row['scenes.studio_id'], doc_count: row['count(*)'] }))
.filter((row) => !!row.key)
|| [];
const total = Number(results.at(-1).data.find((entry) => entry.Variable_name === 'total_found')?.Value) || 0;
return {
@@ -517,6 +540,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
actorIds,
tagIds,
channelIds,
studioIds,
},
};
}
@@ -540,19 +564,24 @@ export async function fetchScenes(filters, rawOptions, reqUser) {
console.timeEnd('manticore sql');
const aggYears = options.aggregateYears && result.aggregations.years.map((bucket) => ({ year: bucket.key, count: bucket.doc_count }));
const entityIds = options.aggregateChannels && [...(result.aggregations.channelIds || []), ...(result.aggregations.studioIds || [])];
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds);
const channelCounts = options.aggregateChannels && countAggregations(entityIds);
console.log('entity ids', entityIds);
console.time('fetch aggregations');
const [aggActors, aggTags, aggChannels] = await Promise.all([
options.aggregateActors ? fetchActorsById(result.aggregations.actorIds.map((bucket) => bucket.key), { order: ['slug', 'asc'], append: actorCounts }) : [],
options.aggregateTags ? fetchTagsById(result.aggregations.tagIds.map((bucket) => bucket.key), { order: [knex.raw('lower(name)'), 'asc'], append: tagCounts }) : [],
options.aggregateChannels ? fetchEntitiesById(result.aggregations.channelIds.map((bucket) => bucket.key), { order: ['slug', 'asc'], append: channelCounts }) : [],
options.aggregateChannels ? fetchEntitiesById(entityIds.map((bucket) => bucket.key), { order: ['slug', 'asc'], append: channelCounts }) : [],
]);
console.log('studio ids', aggChannels.filter((studio) => studio.slug === 'wgcz'));
console.timeEnd('fetch aggregations');
console.time('fetch full');