feat(medusa): Disable subscriber when no search engine is installed (#2958)
This commit is contained in:
@@ -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
|
version: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isSearchEngineInstalledResolutionKey = "isSearchEngineInstalled"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers all services in the services directory
|
* Registers all services in the services directory
|
||||||
*/
|
*/
|
||||||
@@ -447,6 +449,8 @@ export async function registerServices(
|
|||||||
),
|
),
|
||||||
[`searchService`]: aliasTo(name),
|
[`searchService`]: aliasTo(name),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
container.register(isSearchEngineInstalledResolutionKey, asValue(true))
|
||||||
} else if (loaded.prototype instanceof AbstractTaxService) {
|
} else if (loaded.prototype instanceof AbstractTaxService) {
|
||||||
container.registerAdd(
|
container.registerAdd(
|
||||||
"taxProviders",
|
"taxProviders",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import ProductVariantService from "../services/product-variant"
|
import ProductVariantService from "../services/product-variant"
|
||||||
import ProductService from "../services/product"
|
import ProductService from "../services/product"
|
||||||
import { indexTypes } from "medusa-core-utils"
|
import { indexTypes } from "medusa-core-utils"
|
||||||
|
import { isSearchEngineInstalledResolutionKey } from "../loaders/plugins"
|
||||||
|
|
||||||
const searchFields = [
|
const searchFields = [
|
||||||
"id",
|
"id",
|
||||||
@@ -31,12 +32,21 @@ const searchRelations = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
class ProductSearchSubscriber {
|
class ProductSearchSubscriber {
|
||||||
constructor({ eventBusService, searchService, productService }) {
|
constructor(container) {
|
||||||
this.eventBus_ = eventBusService
|
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(
|
this.eventBus_.subscribe(
|
||||||
ProductService.Events.CREATED,
|
ProductService.Events.CREATED,
|
||||||
|
|||||||
Reference in New Issue
Block a user