u
This commit is contained in:
@@ -120,6 +120,12 @@ function toIndexRecord(article, categoryId) {
|
||||
? String(categoryId)
|
||||
: (Array.isArray(article.categoryIds) ? article.categoryIds.join(',') : (article.categories ?? null));
|
||||
|
||||
const firstPhoto = Array.isArray(article.photos) && article.photos.length > 0 ? article.photos[0] : null;
|
||||
const fullHash = article.fullHash ?? firstPhoto?.fullHash ?? null;
|
||||
const thumbHash = article.thumbHash ?? firstPhoto?.thumbHash ?? null;
|
||||
const smallThumbBinary = article.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? null;
|
||||
const photos = article.photos ?? (fullHash ? [{ fullHash, thumbHash }] : []);
|
||||
|
||||
return {
|
||||
...article,
|
||||
id: article.id,
|
||||
@@ -137,6 +143,10 @@ function toIndexRecord(article, categoryId) {
|
||||
categories,
|
||||
isParent: Boolean(article.isParent ?? article.is_parent ?? (childCount > 0)),
|
||||
childCount,
|
||||
fullHash,
|
||||
thumbHash,
|
||||
photos,
|
||||
smallThumbBinary,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -377,14 +387,24 @@ export function updateArticleIndexRecord(article) {
|
||||
let nextItems;
|
||||
if (existingIndex >= 0) {
|
||||
const existing = items[existingIndex];
|
||||
const firstPhoto = Array.isArray(article.photos) && article.photos.length > 0 ? article.photos[0] : null;
|
||||
const hasPhotosProp = 'photos' in article;
|
||||
const fullHash = article.fullHash ?? firstPhoto?.fullHash ?? (hasPhotosProp ? null : existing.fullHash);
|
||||
const thumbHash = article.thumbHash ?? firstPhoto?.thumbHash ?? (hasPhotosProp ? null : existing.thumbHash);
|
||||
const photos = article.photos ?? (hasPhotosProp ? [] : (existing.photos ?? []));
|
||||
const smallThumbBinary = article.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? (hasPhotosProp ? null : existing.smallThumbBinary);
|
||||
|
||||
nextItems = [...items];
|
||||
nextItems[existingIndex] = {
|
||||
...existing,
|
||||
...record,
|
||||
categories: record.categories ?? existing.categories,
|
||||
smallThumbBinary: article.smallThumbBinary ?? article.photos?.[0]?.smallThumbBinary ?? existing.smallThumbBinary,
|
||||
brand: article.brand ?? existing.brand,
|
||||
brandName: article.brand?.name ?? article.brandName ?? existing.brandName,
|
||||
fullHash,
|
||||
thumbHash,
|
||||
photos,
|
||||
smallThumbBinary,
|
||||
};
|
||||
} else {
|
||||
nextItems = [...items, record];
|
||||
|
||||
Reference in New Issue
Block a user