feat(medusa): Disable subscriber when no search engine is installed (#2958)
This commit is contained in:
committed by
GitHub
parent
a93d5d437c
commit
baeacd1cc5
5
.changeset/slimy-candles-wait.md
Normal file
5
.changeset/slimy-candles-wait.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat: Deactivate search service product subscribers when search engine not enabled
|
||||
@@ -52,6 +52,8 @@ type PluginDetails = {
|
||||
version: string
|
||||
}
|
||||
|
||||
export const isSearchEngineInstalledResolutionKey = "isSearchEngineInstalled"
|
||||
|
||||
/**
|
||||
* Registers all services in the services directory
|
||||
*/
|
||||
@@ -447,6 +449,8 @@ export async function registerServices(
|
||||
),
|
||||
[`searchService`]: aliasTo(name),
|
||||
})
|
||||
|
||||
container.register(isSearchEngineInstalledResolutionKey, asValue(true))
|
||||
} else if (loaded.prototype instanceof AbstractTaxService) {
|
||||
container.registerAdd(
|
||||
"taxProviders",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import ProductVariantService from "../services/product-variant"
|
||||
import ProductService from "../services/product"
|
||||
import { indexTypes } from "medusa-core-utils"
|
||||
import { isSearchEngineInstalledResolutionKey } from "../loaders/plugins"
|
||||
|
||||
const searchFields = [
|
||||
"id",
|
||||
@@ -31,12 +32,21 @@ const searchRelations = [
|
||||
]
|
||||
|
||||
class ProductSearchSubscriber {
|
||||
constructor({ eventBusService, searchService, productService }) {
|
||||
this.eventBus_ = eventBusService
|
||||
constructor(container) {
|
||||
this.eventBus_ = container.eventBusService
|
||||
this.searchService_ = container.searchService
|
||||
this.productService_ = container.productService
|
||||
|
||||
this.searchService_ = searchService
|
||||
/**
|
||||
* Do not subscribe to any event in case no search engine have been installed.
|
||||
* If some events need to be subscribed out of the search engine reason, they can be subscribed above this comment
|
||||
*/
|
||||
|
||||
this.productService_ = productService
|
||||
try {
|
||||
container[isSearchEngineInstalledResolutionKey]
|
||||
} catch (e) {
|
||||
return this
|
||||
}
|
||||
|
||||
this.eventBus_.subscribe(
|
||||
ProductService.Events.CREATED,
|
||||
|
||||
Reference in New Issue
Block a user