Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updateProductOrVariant({
ctx: rawContext,
productId,
variantId,
}: UpdateProductOrVariantMessage['data']): Observable {
const ctx = RequestContext.fromObject(rawContext);
return defer(async () => {
if (productId) {
await this.updateProduct(ctx, productId);
} else if (variantId) {
await this.updateProductVariant(ctx, variantId);
}
return true;
});
}
reindex({ ctx: rawContext }: ReindexMessage['data']): Observable {
const ctx = RequestContext.fromObject(rawContext);
const { batchSize } = this.options;
return new Observable(observer => {
(async () => {
const timeStart = Date.now();
const qb = this.getSearchIndexQueryBuilder();
const count = await qb.where('variants__product.deletedAt IS NULL').getCount();
Logger.verbose(`Reindexing ${count} ProductVariants`, loggerCtx);
const batches = Math.ceil(count / batchSize);
let variantsInProduct: ProductVariant[] = [];
for (let i = 0; i < batches; i++) {
Logger.verbose(`Processing batch ${i + 1} of ${batches}`, loggerCtx);
const variants = await this.getBatch(ctx, qb, i);
updateVariantsById({
ctx: rawContext,
ids,
}: UpdateVariantsByIdMessage['data']): Observable {
const ctx = RequestContext.fromObject(rawContext);
const { batchSize } = this.options;
return new Observable(observer => {
(async () => {
const timeStart = Date.now();
if (ids.length) {
const batches = Math.ceil(ids.length / batchSize);
Logger.verbose(`Updating ${ids.length} variants...`);
let variantsInProduct: ProductVariant[] = [];
for (let i = 0; i < batches; i++) {
const begin = i * batchSize;
const end = begin + batchSize;
Logger.verbose(`Updating ids from index ${begin} to ${end}`);