|
@@ -162,7 +162,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
async deleteVariants({ ctx: rawContext, variantIds }: UpdateVariantMessageData): Promise<boolean> {
|
|
async deleteVariants({ ctx: rawContext, variantIds }: UpdateVariantMessageData): Promise<boolean> {
|
|
|
const productIds = await this.getProductIdsByVariantIds(variantIds);
|
|
const productIds = await this.getProductIdsByVariantIds(variantIds);
|
|
|
for (const productId of productIds) {
|
|
for (const productId of productIds) {
|
|
|
- await this.deleteProductInternal(productId);
|
|
|
|
|
|
|
+ await this.updateProductsInternal([productId]);
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -229,6 +229,8 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
.where('product.deletedAt IS NULL')
|
|
.where('product.deletedAt IS NULL')
|
|
|
.getMany();
|
|
.getMany();
|
|
|
|
|
|
|
|
|
|
+ Logger.verbose(`Reindexing ${productIds.length} Products`, loggerCtx);
|
|
|
|
|
+
|
|
|
let finishedProductsCount = 0;
|
|
let finishedProductsCount = 0;
|
|
|
for (const { id: productId } of productIds) {
|
|
for (const { id: productId } of productIds) {
|
|
|
await this.updateProductsInternal([productId]);
|
|
await this.updateProductsInternal([productId]);
|
|
@@ -396,7 +398,9 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
updatedProductVariants.forEach(v => (v.enabled = false));
|
|
updatedProductVariants.forEach(v => (v.enabled = false));
|
|
|
}
|
|
}
|
|
|
Logger.verbose(`Updating Product (${productId})`, loggerCtx);
|
|
Logger.verbose(`Updating Product (${productId})`, loggerCtx);
|
|
|
- if (updatedProductVariants.length) await this.updateVariantsInternal(updatedProductVariants);
|
|
|
|
|
|
|
+ if (updatedProductVariants.length) {
|
|
|
|
|
+ await this.updateVariantsInternal(updatedProductVariants);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const languageVariants = product.translations.map(t => t.languageCode);
|
|
const languageVariants = product.translations.map(t => t.languageCode);
|
|
|
|
|
|
|
@@ -441,7 +445,6 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private async deleteProductInternal(productId: ID) {
|
|
private async deleteProductInternal(productId: ID) {
|
|
|
- Logger.verbose(`Deleting 1 Product (${productId})`, loggerCtx);
|
|
|
|
|
const channels = await this.connection
|
|
const channels = await this.connection
|
|
|
.getRepository(Channel)
|
|
.getRepository(Channel)
|
|
|
.createQueryBuilder('channel')
|
|
.createQueryBuilder('channel')
|
|
@@ -451,6 +454,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
relations: ['variants'],
|
|
relations: ['variants'],
|
|
|
});
|
|
});
|
|
|
if (product) {
|
|
if (product) {
|
|
|
|
|
+ Logger.verbose(`Deleting 1 Product (id: ${productId})`, loggerCtx);
|
|
|
const operations: BulkOperation[] = [];
|
|
const operations: BulkOperation[] = [];
|
|
|
for (const { id: channelId } of channels) {
|
|
for (const { id: channelId } of channels) {
|
|
|
const languageVariants = product.translations.map(t => t.languageCode);
|
|
const languageVariants = product.translations.map(t => t.languageCode);
|
|
@@ -494,6 +498,9 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
indexName: string,
|
|
indexName: string,
|
|
|
operations: Array<BulkOperation | BulkOperationDoc<VariantIndexItem | ProductIndexItem>>,
|
|
operations: Array<BulkOperation | BulkOperationDoc<VariantIndexItem | ProductIndexItem>>,
|
|
|
) {
|
|
) {
|
|
|
|
|
+ if (operations.length === 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
const fullIndexName = this.options.indexPrefix + indexName;
|
|
const fullIndexName = this.options.indexPrefix + indexName;
|
|
|
const { body }: { body: BulkResponseBody } = await this.client.bulk({
|
|
const { body }: { body: BulkResponseBody } = await this.client.bulk({
|
|
@@ -519,7 +526,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- Logger.verbose(
|
|
|
|
|
|
|
+ Logger.debug(
|
|
|
`Executed ${body.items.length} bulk operations on index [${fullIndexName}]`,
|
|
`Executed ${body.items.length} bulk operations on index [${fullIndexName}]`,
|
|
|
loggerCtx,
|
|
loggerCtx,
|
|
|
);
|
|
);
|
|
@@ -527,7 +534,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
return body;
|
|
return body;
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
Logger.error(`Error when attempting to run bulk operations [${e.toString()}]`, loggerCtx);
|
|
Logger.error(`Error when attempting to run bulk operations [${e.toString()}]`, loggerCtx);
|
|
|
- Logger.error('Error details: ' + JSON.stringify(e.body && e.body.error, null, 2), loggerCtx);
|
|
|
|
|
|
|
+ Logger.error('Error details: ' + JSON.stringify(e.body?.error, null, 2), loggerCtx);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -645,7 +652,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
|
|
|
const productTranslation = this.getTranslation(product, ctx.languageCode);
|
|
const productTranslation = this.getTranslation(product, ctx.languageCode);
|
|
|
return {
|
|
return {
|
|
|
channelId: ctx.channelId,
|
|
channelId: ctx.channelId,
|
|
|
- languageCode: languageCode,
|
|
|
|
|
|
|
+ languageCode,
|
|
|
sku: '',
|
|
sku: '',
|
|
|
slug: productTranslation.slug,
|
|
slug: productTranslation.slug,
|
|
|
productId: product.id,
|
|
productId: product.id,
|