Fixed pagination. Added entity page channel tile expand.
This commit is contained in:
@@ -35,13 +35,13 @@ export function curateActor(actor, context = {}) {
|
||||
tattoos: actor.tattoos,
|
||||
hasPiercings: actor.has_piercings,
|
||||
piercings: actor.piercings,
|
||||
origin: {
|
||||
origin: actor.birth_country_alpha2 && {
|
||||
country: actor.birth_country_alpha2 && {
|
||||
alpha2: actor.birth_country_alpha2,
|
||||
name: actor.birth_country_name,
|
||||
},
|
||||
},
|
||||
residence: {
|
||||
residence: actor.residence_country_alpha2 && {
|
||||
country: actor.residence_country_alpha2 && {
|
||||
alpha2: actor.residence_country_alpha2,
|
||||
name: actor.residence_country_name,
|
||||
|
||||
@@ -14,15 +14,39 @@ function curateEntity(entity, context) {
|
||||
name: entity.name,
|
||||
slug: entity.slug,
|
||||
type: entity.type,
|
||||
url: entity.url,
|
||||
isIndependent: entity.independent,
|
||||
hasLogo: entity.has_logo,
|
||||
parent: curateEntity(entity.parent, context),
|
||||
children: context?.children?.filter((child) => child.parent_id === entity.id).map((child) => curateEntity({ ...child, parent: entity }, { parent: entity })) || [],
|
||||
...context?.append?.[entity.id],
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchEntities(options) {
|
||||
const entities = await knex('entities')
|
||||
.modify((builder) => {
|
||||
if (options.type === 'primary') {
|
||||
builder
|
||||
.where('type', 'network')
|
||||
.orWhere('independent', true)
|
||||
.orWhereNull('parent_id');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.type) {
|
||||
builder.where('type', options.type);
|
||||
}
|
||||
})
|
||||
.orderBy(...(options.order || ['name', 'asc']))
|
||||
.limit(options.limit || 1000);
|
||||
|
||||
return entities.map((entityEntry) => curateEntity(entityEntry));
|
||||
}
|
||||
|
||||
export async function fetchEntitiesById(entityIds, options = {}) {
|
||||
const [entities] = await Promise.all([
|
||||
const [entities, children] = await Promise.all([
|
||||
knex('entities')
|
||||
.select('entities.*', knex.raw('row_to_json(parents) as parent'))
|
||||
.whereIn('entities.id', entityIds)
|
||||
@@ -33,10 +57,16 @@ export async function fetchEntitiesById(entityIds, options = {}) {
|
||||
}
|
||||
})
|
||||
.groupBy('entities.id', 'parents.id'),
|
||||
options.includeChildren ? knex('entities')
|
||||
.whereIn('entities.parent_id', entityIds)
|
||||
.orderBy('slug') : [],
|
||||
]);
|
||||
|
||||
if (options.order) {
|
||||
return entities.map((entityEntry) => curateEntity(entityEntry, { append: options.append }));
|
||||
return entities.map((entityEntry) => curateEntity(entityEntry, {
|
||||
append: options.append,
|
||||
children,
|
||||
}));
|
||||
}
|
||||
|
||||
const curatedEntities = entityIds.map((entityId) => {
|
||||
@@ -47,7 +77,10 @@ export async function fetchEntitiesById(entityIds, options = {}) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return curateEntity(entity, { append: options.append });
|
||||
return curateEntity(entity, {
|
||||
append: options.append,
|
||||
children,
|
||||
});
|
||||
}).filter(Boolean);
|
||||
|
||||
return curatedEntities;
|
||||
|
||||
@@ -183,6 +183,10 @@ function buildQuery(filters = {}) {
|
||||
sort = [{ created_at: 'desc' }, { effective_date: 'asc' }];
|
||||
}
|
||||
|
||||
if (filters.scope === 'likes') {
|
||||
sort = [{ stashed: 'desc' }, { effective_date: 'desc' }];
|
||||
}
|
||||
|
||||
if (filters.tagIds) {
|
||||
filters.tagIds.forEach((tagId) => {
|
||||
query.bool.must.push({ equals: { 'any(tag_ids)': tagId } });
|
||||
@@ -272,6 +276,7 @@ export async function fetchScenes(filters, rawOptions) {
|
||||
offset: (options.page - 1) * options.limit,
|
||||
sort,
|
||||
aggs: buildAggregates(options),
|
||||
max_matches: 5000,
|
||||
});
|
||||
|
||||
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds?.buckets);
|
||||
|
||||
Reference in New Issue
Block a user