Improved actor bio responsiveness, showing secondary actor photos.
This commit is contained in:
191
src/actors.js
191
src/actors.js
@@ -58,8 +58,21 @@ export function curateActor(actor, context = {}) {
|
||||
path: actor.avatar.path,
|
||||
thumbnail: actor.avatar.thumbnail,
|
||||
lazy: actor.avatar.lazy,
|
||||
width: actor.avatar.width,
|
||||
height: actor.avatar.height,
|
||||
isS3: actor.avatar.is_s3,
|
||||
credit: actor.avatar.credit,
|
||||
},
|
||||
photos: context.photos?.map((photo) => ({
|
||||
id: photo.id,
|
||||
path: photo.path,
|
||||
thumbnail: photo.thumbnail,
|
||||
lazy: photo.lazy,
|
||||
width: photo.width,
|
||||
height: photo.height,
|
||||
isS3: photo.is_s3,
|
||||
credit: photo.credit,
|
||||
})),
|
||||
createdAt: actor.created_at,
|
||||
updatedAt: actor.updated_at,
|
||||
likes: actor.stashed,
|
||||
@@ -96,7 +109,7 @@ export function sortActorsByGender(actors, context = {}) {
|
||||
}
|
||||
|
||||
export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
const [actors, stashes] = await Promise.all([
|
||||
const [actors, photos, stashes] = await Promise.all([
|
||||
knex('actors')
|
||||
.select(
|
||||
'actors.*',
|
||||
@@ -115,6 +128,14 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
builder.orderBy(...options.order);
|
||||
}
|
||||
}),
|
||||
knex('actors_profiles')
|
||||
.select('actors_profiles.actor_id', 'media.*')
|
||||
.leftJoin('actors', 'actors.id', 'actors_profiles.actor_id')
|
||||
.leftJoin('media', 'media.id', 'actors_profiles.avatar_media_id')
|
||||
.whereIn('actor_id', actorIds)
|
||||
.whereNotNull('actors_profiles.avatar_media_id')
|
||||
.whereNot('actors_profiles.avatar_media_id', knex.raw('actors.avatar_media_id')) // don't include main avatar as photo
|
||||
.groupBy('actors_profiles.actor_id', 'media.id', 'media.hash'),
|
||||
reqUser
|
||||
? knex('stashes_actors')
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_actors.stash_id')
|
||||
@@ -140,6 +161,7 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
|
||||
return curateActor(actor, {
|
||||
stashes: stashes.filter((stash) => stash.actor_id === actor.id),
|
||||
photos: photos.filter((photo) => photo.actor_id === actor.id),
|
||||
append: options.append,
|
||||
});
|
||||
}).filter(Boolean);
|
||||
@@ -160,173 +182,6 @@ function curateOptions(options) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
const sortMap = {
|
||||
likes: 'stashed',
|
||||
scenes: 'scenes',
|
||||
relevance: '_score',
|
||||
};
|
||||
|
||||
function getSort(order) {
|
||||
if (order[0] === 'name') {
|
||||
return [{
|
||||
slug: order[1],
|
||||
}];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
[sortMap[order[0]]]: order[1],
|
||||
},
|
||||
{
|
||||
slug: 'asc', // sort by name where primary order is equal
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function buildQuery(filters) {
|
||||
const query = {
|
||||
bool: {
|
||||
must: [],
|
||||
},
|
||||
};
|
||||
|
||||
const expressions = {
|
||||
age: 'if(date_of_birth, floor((now() - date_of_birth) / 31556952), 0)',
|
||||
};
|
||||
|
||||
if (filters.query) {
|
||||
query.bool.must.push({
|
||||
match: {
|
||||
name: filters.query,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
['gender', 'country'].forEach((attribute) => {
|
||||
if (filters[attribute]) {
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
[attribute]: filters[attribute],
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
['age', 'height', 'weight'].forEach((attribute) => {
|
||||
if (filters[attribute]) {
|
||||
query.bool.must.push({
|
||||
range: {
|
||||
[attribute]: {
|
||||
gte: filters[attribute][0],
|
||||
lte: filters[attribute][1],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (filters.dateOfBirth && filters.dobType === 'dateOfBirth') {
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
date_of_birth: Math.floor(filters.dateOfBirth.getTime() / 1000),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.dateOfBirth && filters.dobType === 'birthday') {
|
||||
expressions.month_of_birth = 'month(date_of_birth)';
|
||||
expressions.day_of_birth = 'day(date_of_birth)';
|
||||
|
||||
const month = filters.dateOfBirth.getMonth() + 1;
|
||||
const day = filters.dateOfBirth.getDate();
|
||||
|
||||
query.bool.must.push({
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
equals: {
|
||||
month_of_birth: month,
|
||||
},
|
||||
},
|
||||
{
|
||||
equals: {
|
||||
day_of_birth: day,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.cup) {
|
||||
expressions.cup_in_range = `regex(cup, '^[${filters.cup[0]}-${filters.cup[1]}]')`;
|
||||
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
cup_in_range: 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof filters.naturalBoobs === 'boolean') {
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
natural_boobs: filters.naturalBoobs ? 2 : 1, // manticore boolean does not support null, so 0 = null, 1 = false (enhanced), 2 = true (natural)
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.requireAvatar) {
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
has_avatar: 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return { query, expressions };
|
||||
}
|
||||
|
||||
async function queryManticoreJson(filters, options) {
|
||||
const { query, expressions } = buildQuery(filters);
|
||||
|
||||
const result = await searchApi.search({
|
||||
index: 'actors',
|
||||
query,
|
||||
expressions,
|
||||
limit: options.limit,
|
||||
offset: (options.page - 1) * options.limit,
|
||||
sort: getSort(options.order, filters),
|
||||
aggs: {
|
||||
countries: {
|
||||
terms: {
|
||||
field: 'country',
|
||||
size: 300,
|
||||
},
|
||||
sort: [{ country: { order: 'asc' } }],
|
||||
},
|
||||
},
|
||||
options: {
|
||||
max_matches: config.database.manticore.maxMatches,
|
||||
max_query_time: config.database.manticore.maxQueryTime,
|
||||
},
|
||||
});
|
||||
|
||||
const actors = result.hits.hits.map((hit) => ({
|
||||
id: hit._id,
|
||||
...hit._source,
|
||||
_score: hit._score,
|
||||
}));
|
||||
|
||||
return {
|
||||
actors,
|
||||
total: result.hits.total,
|
||||
aggregations: result.aggregations && Object.fromEntries(Object.entries(result.aggregations).map(([key, { buckets }]) => [key, buckets])),
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
async function queryManticoreSql(filters, options, _reqUser) {
|
||||
const aggSize = config.database.manticore.maxAggregateSize;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user