diff --git a/packages/core/src/plugin/default-search-plugin/index.ts b/packages/core/src/plugin/default-search-plugin/index.ts index 4fd33590bf..594e7e0ffd 100644 --- a/packages/core/src/plugin/default-search-plugin/index.ts +++ b/packages/core/src/plugin/default-search-plugin/index.ts @@ -9,3 +9,4 @@ export * from './search-strategy/postgres-search-strategy'; export * from './search-strategy/sqlite-search-strategy'; export * from './search-strategy/search-strategy'; export * from './search-strategy/search-strategy-common'; +export * from './indexer/mutable-request-context'; diff --git a/packages/elasticsearch-plugin/src/indexing/indexer.controller.ts b/packages/elasticsearch-plugin/src/indexing/indexer.controller.ts index 55c0512f66..c20b59aff0 100644 --- a/packages/elasticsearch-plugin/src/indexing/indexer.controller.ts +++ b/packages/elasticsearch-plugin/src/indexing/indexer.controller.ts @@ -16,6 +16,7 @@ import { InternalServerError, LanguageCode, Logger, + MutableRequestContext, Product, ProductPriceApplicator, ProductVariant, @@ -47,7 +48,6 @@ import { } from '../types'; import { createIndices, getClient, getIndexNameByAlias } from './indexing-utils'; -import { MutableRequestContext } from './mutable-request-context'; const REINDEX_CHUNK_SIZE = 2500; const REINDEX_OPERATION_CHUNK_SIZE = 3000; diff --git a/packages/elasticsearch-plugin/src/indexing/mutable-request-context.ts b/packages/elasticsearch-plugin/src/indexing/mutable-request-context.ts deleted file mode 100644 index 02106d9a84..0000000000 --- a/packages/elasticsearch-plugin/src/indexing/mutable-request-context.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Channel, ID, RequestContext, SerializedRequestContext } from '@vendure/core'; - -/** - * @description - * This is used during search index creation to allow us to use a single - * RequestContext, but mutate the Channel. In this way, we can take - * full advantage of the RequestContextCacheService, and _massively_ cut - * down on the number of DB calls being made during indexing. - */ -export class MutableRequestContext extends RequestContext { - constructor(options: ConstructorParameters[0]) { - super(options); - } - private mutatedChannel: Channel | undefined; - - setChannel(channel: Channel) { - this.mutatedChannel = channel; - } - - get channel(): Channel { - return this.mutatedChannel ?? super.channel; - } - - get channelId(): ID { - return this.mutatedChannel?.id ?? super.channelId; - } - - static deserialize(ctxObject: SerializedRequestContext): MutableRequestContext { - return new MutableRequestContext({ - req: ctxObject._req , - apiType: ctxObject._apiType, - channel: new Channel(ctxObject._channel), - session: { - ...ctxObject._session, - expires: ctxObject._session?.expires && new Date(ctxObject._session.expires), - }, - languageCode: ctxObject._languageCode, - isAuthorized: ctxObject._isAuthorized, - authorizedAsOwnerOnly: ctxObject._authorizedAsOwnerOnly, - }); - } -}