Added functional stash button on scene tiles.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import config from 'config';
|
||||
|
||||
import knex from './knex.js';
|
||||
import { knexOwner as knex } from './knex.js';
|
||||
import { searchApi } from './manticore.js';
|
||||
import { HttpError } from './errors.js';
|
||||
import { fetchActorsById, curateActor, sortActorsByGender } from './actors.js';
|
||||
import { fetchTagsById } from './tags.js';
|
||||
import { fetchEntitiesById } from './entities.js';
|
||||
import { curateStash } from './stashes.js';
|
||||
|
||||
function curateMedia(media) {
|
||||
if (!media) {
|
||||
@@ -66,14 +67,15 @@ function curateScene(rawScene, assets) {
|
||||
})),
|
||||
poster: curateMedia(assets.poster),
|
||||
photos: assets.photos.map((photo) => curateMedia(photo)),
|
||||
stashes: assets.stashes?.map((stash) => curateStash(stash)) || [],
|
||||
createdBatchId: rawScene.created_batch_id,
|
||||
updatedBatchId: rawScene.updated_batch_id,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchScenesById(sceneIds) {
|
||||
const [scenes, channels, actors, directors, tags, posters, photos] = await Promise.all([
|
||||
knex('releases').whereIn('id', sceneIds),
|
||||
export async function fetchScenesById(sceneIds, reqUser) {
|
||||
const [scenes, channels, actors, directors, tags, posters, photos, stashes] = await Promise.all([
|
||||
knex('releases').whereIn('releases.id', sceneIds),
|
||||
knex('releases')
|
||||
.select('channels.*', 'networks.id as network_id', 'networks.slug as network_slug', 'networks.name as network_name', 'networks.type as network_type')
|
||||
.whereIn('releases.id', sceneIds)
|
||||
@@ -92,9 +94,9 @@ export async function fetchScenesById(sceneIds) {
|
||||
knex.raw('COALESCE(residence_countries.alias, residence_countries.name) as residence_country_name'),
|
||||
*/
|
||||
)
|
||||
.whereIn('release_id', sceneIds)
|
||||
.leftJoin('actors', 'actors.id', 'releases_actors.actor_id')
|
||||
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id'),
|
||||
.leftJoin('actors_meta', 'actors_meta.actor_id', 'actors.id')
|
||||
.whereIn('release_id', sceneIds),
|
||||
/*
|
||||
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors_meta.birth_country_alpha2')
|
||||
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors_meta.residence_country_alpha2'),
|
||||
@@ -104,9 +106,9 @@ export async function fetchScenesById(sceneIds) {
|
||||
.leftJoin('actors as directors', 'directors.id', 'releases_directors.director_id'),
|
||||
knex('releases_tags')
|
||||
.select('id', 'slug', 'name', 'release_id')
|
||||
.leftJoin('tags', 'tags.id', 'releases_tags.tag_id')
|
||||
.whereNotNull('tags.id')
|
||||
.whereIn('release_id', sceneIds)
|
||||
.leftJoin('tags', 'tags.id', 'releases_tags.tag_id')
|
||||
.orderBy('priority', 'desc'),
|
||||
knex('releases_posters')
|
||||
.whereIn('release_id', sceneIds)
|
||||
@@ -114,6 +116,12 @@ export async function fetchScenesById(sceneIds) {
|
||||
knex('releases_photos')
|
||||
.whereIn('release_id', sceneIds)
|
||||
.leftJoin('media', 'media.id', 'releases_photos.media_id'),
|
||||
reqUser
|
||||
? knex('stashes_scenes')
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_scenes.stash_id')
|
||||
.where('stashes.user_id', reqUser.id)
|
||||
.whereIn('stashes_scenes.scene_id', sceneIds)
|
||||
: [],
|
||||
]);
|
||||
|
||||
return sceneIds.map((sceneId) => {
|
||||
@@ -129,6 +137,7 @@ export async function fetchScenesById(sceneIds) {
|
||||
const sceneTags = tags.filter((tag) => tag.release_id === sceneId);
|
||||
const scenePoster = posters.find((poster) => poster.release_id === sceneId);
|
||||
const scenePhotos = photos.filter((photo) => photo.release_id === sceneId);
|
||||
const sceneStashes = stashes.filter((stash) => stash.scene_id === sceneId);
|
||||
|
||||
return curateScene(scene, {
|
||||
channel: sceneChannel,
|
||||
@@ -137,6 +146,7 @@ export async function fetchScenesById(sceneIds) {
|
||||
tags: sceneTags,
|
||||
poster: scenePoster,
|
||||
photos: scenePhotos,
|
||||
stashes: sceneStashes,
|
||||
});
|
||||
}).filter(Boolean);
|
||||
}
|
||||
@@ -294,7 +304,7 @@ function countAggregations(buckets) {
|
||||
return Object.fromEntries(buckets.map((bucket) => [bucket.key, { count: bucket.doc_count }]));
|
||||
}
|
||||
|
||||
export async function fetchScenes(filters, rawOptions) {
|
||||
export async function fetchScenes(filters, rawOptions, reqUser) {
|
||||
const options = curateOptions(rawOptions);
|
||||
const { query, sort } = buildQuery(filters);
|
||||
|
||||
@@ -302,6 +312,8 @@ export async function fetchScenes(filters, rawOptions) {
|
||||
console.log('options', options);
|
||||
console.log('query', query.bool.must);
|
||||
|
||||
console.log('request user', reqUser);
|
||||
|
||||
console.time('manticore');
|
||||
|
||||
const result = await searchApi.search({
|
||||
@@ -329,8 +341,6 @@ export async function fetchScenes(filters, rawOptions) {
|
||||
|
||||
console.timeEnd('manticore');
|
||||
|
||||
console.log('hits', result.hits.hits.length);
|
||||
|
||||
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds?.buckets);
|
||||
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds?.buckets);
|
||||
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds?.buckets);
|
||||
@@ -346,7 +356,7 @@ export async function fetchScenes(filters, rawOptions) {
|
||||
console.timeEnd('fetch aggregations');
|
||||
|
||||
const sceneIds = result.hits.hits.map((hit) => Number(hit._id));
|
||||
const scenes = await fetchScenesById(sceneIds);
|
||||
const scenes = await fetchScenesById(sceneIds, reqUser);
|
||||
|
||||
return {
|
||||
scenes,
|
||||
|
||||
Reference in New Issue
Block a user