feat(medusa): Disable subscriber when no search engine is installed (#2958)

This commit is contained in:
Adrien de Peretti
2023-01-07 15:58:06 +01:00
committed by GitHub
parent a93d5d437c
commit baeacd1cc5
3 changed files with 23 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
feat: Deactivate search service product subscribers when search engine not enabled
+4
View File
@@ -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",
+14 -4
View File
@@ -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,