Using actors avatars table for secondary profile photos.
This commit is contained in:
@@ -110,8 +110,15 @@ export function curateActor(actor, context = {}) {
|
||||
description: profile.description,
|
||||
descriptionHash: profile.description_hash,
|
||||
entity: curateEntity({ ...profile.entity, parent: profile.parent_entity }),
|
||||
avatar: curateMedia(profile.avatar),
|
||||
// avatars: profile.avatars.map((avatar) => curateMedia(avatar)),
|
||||
})),
|
||||
photos: context.photos
|
||||
?.map((photo) => ({
|
||||
...curateMedia(photo),
|
||||
isAvatar: photo.id === actor.avatar?.id,
|
||||
profileIds: photo.profile_ids,
|
||||
}))
|
||||
.toSorted((photoA, photoB) => photoB.isAvatar - photoA.isAvatar),
|
||||
createdAt: actor.created_at,
|
||||
updatedAt: actor.updated_at,
|
||||
scenes: actor.scenes,
|
||||
@@ -149,7 +156,7 @@ export function sortActorsByGender(actors, context = {}) {
|
||||
}
|
||||
|
||||
export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
const [actors, profiles, stashes] = await Promise.all([
|
||||
const [actors, profiles, photos, stashes] = await Promise.all([
|
||||
knex('actors')
|
||||
.select(
|
||||
'actors.*',
|
||||
@@ -171,13 +178,29 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
}
|
||||
}),
|
||||
knex('actors_profiles')
|
||||
.select('actors_profiles.*', knex.raw('row_to_json(entities) as entity'), knex.raw('row_to_json(parents) as parent_entity'), knex.raw('row_to_json(media) as avatar'))
|
||||
.select(
|
||||
'actors_profiles.*',
|
||||
knex.raw('row_to_json(entities) as entity'),
|
||||
knex.raw('row_to_json(parents) as parent_entity'),
|
||||
// knex.raw('coalesce(json_agg(media) filter (where media.id is not null), \'[]\') as avatars'),
|
||||
)
|
||||
.leftJoin('actors', 'actors.id', 'actors_profiles.actor_id')
|
||||
.leftJoin('entities', 'entities.id', 'actors_profiles.entity_id')
|
||||
.leftJoin('entities as parents', 'parents.id', 'entities.parent_id')
|
||||
.leftJoin('media', 'media.id', 'actors_profiles.avatar_media_id')
|
||||
.leftJoin('actors_avatars', 'actors_avatars.profile_id', 'actors_profiles.id')
|
||||
// .leftJoin('media', 'media.id', 'actors_avatars.media_id')
|
||||
.whereIn('actors_profiles.actor_id', actorIds)
|
||||
.groupBy('actors_profiles.id', 'entities.id', 'parents.id'),
|
||||
knex('actors_avatars')
|
||||
.select(
|
||||
'media.*',
|
||||
'actors_avatars.actor_id',
|
||||
knex.raw('json_agg(actors_avatars.profile_id) as profile_ids'),
|
||||
)
|
||||
.whereIn('actor_id', actorIds)
|
||||
.groupBy('actors_profiles.id', 'entities.id', 'parents.id', 'media.id'),
|
||||
.leftJoin('media', 'media.id', 'actors_avatars.media_id')
|
||||
.groupBy('media.id', 'actors_avatars.actor_id', 'actors_avatars.created_at')
|
||||
.orderBy('actors_avatars.created_at', 'desc'),
|
||||
reqUser
|
||||
? knex('stashes_actors')
|
||||
.leftJoin('stashes', 'stashes.id', 'stashes_actors.stash_id')
|
||||
@@ -204,6 +227,7 @@ export async function fetchActorsById(actorIds, options = {}, reqUser) {
|
||||
return curateActor(actor, {
|
||||
stashes: stashes.filter((stash) => stash.actor_id === actor.id),
|
||||
profiles: profiles.filter((profile) => profile.actor_id === actor.id),
|
||||
photos: photos.filter((photo) => photo.actor_id === actor.id),
|
||||
append: options.append,
|
||||
});
|
||||
}).filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user