Skip to content

Commit

Permalink
fix(core, elasticsearch-plugin) Reindex variants on stock movement ev…
Browse files Browse the repository at this point in the history
…ents (#3113)
  • Loading branch information
LeftoversTodayAppAdmin authored Nov 8, 2024
1 parent dec72e7 commit 82512ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { JobQueueService } from '../../job-queue/job-queue.service';
import { PluginCommonModule } from '../plugin-common.module';
import { VendurePlugin } from '../vendure-plugin';

import { StockMovementEvent } from '../../event-bus/events/stock-movement-event';
import { stockStatusExtension } from './api/api-extensions';
import { AdminFulltextSearchResolver, ShopFulltextSearchResolver } from './api/fulltext-search.resolver';
import { BUFFER_SEARCH_INDEX_UPDATES, PLUGIN_INIT_OPTIONS } from './constants';
Expand Down Expand Up @@ -166,6 +167,13 @@ export class DefaultSearchPlugin implements OnApplicationBootstrap, OnApplicatio
}
});

this.eventBus.ofType(StockMovementEvent).subscribe(event => {
return this.searchIndexService.updateVariants(
event.ctx,
event.stockMovements.map(m => m.productVariant),
);
});

// TODO: Remove this buffering logic because because we have dedicated buffering based on #1137
const collectionModification$ = this.eventBus.ofType(CollectionModificationEvent);
const closingNotifier$ = collectionModification$.pipe(debounceTime(50));
Expand Down
8 changes: 8 additions & 0 deletions packages/elasticsearch-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ProductVariantChannelEvent,
ProductVariantEvent,
SearchJobBufferService,
StockMovementEvent,
TaxRateModificationEvent,
Type,
VendurePlugin,
Expand Down Expand Up @@ -349,6 +350,13 @@ export class ElasticsearchPlugin implements OnApplicationBootstrap {
}
});

this.eventBus.ofType(StockMovementEvent).subscribe(event => {
return this.elasticsearchIndexService.updateVariants(
event.ctx,
event.stockMovements.map(m => m.productVariant),
);
});

// TODO: Remove this buffering logic because because we have dedicated buffering based on #1137
const collectionModification$ = this.eventBus.ofType(CollectionModificationEvent);
const closingNotifier$ = collectionModification$.pipe(debounceTime(50));
Expand Down

0 comments on commit 82512ee

Please sign in to comment.