fix(medusa, types, utils, event-bus-local): Revert retrieveSubscribers (#4002)

* fix(medusa, event-bus-redis, event-bus-local): Revert retrieveSubscribers as the wildcard prevent us from filtering

* Create calm-eggs-collect.md

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de PerettiandOliver Windall Juhl authored and GitHub committed 2023-05-03 18:55:45 +02:00
1 parent bcaaa0288b
commit 0e488e71b1
5 files changed
+13 -27

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
---
"@medusajs/event-bus-local": patch
"@medusajs/medusa": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---
fix(medusa, event-bus-redis, event-bus-local): Revert retrieveSubscribers as the wildcard prevent us from filtering
@@ -86,7 +86,7 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
subscriber: Subscriber, subscriber: Subscriber,
context?: EventBusTypes.SubscriberContext context?: EventBusTypes.SubscriberContext
): this { ): this {
const existingSubscribers = this.retrieveSubscribers(event) const existingSubscribers = this.eventToSubscribersMap_.get(event)
if (existingSubscribers?.length) { if (existingSubscribers?.length) {
const subIndex = existingSubscribers?.findIndex( const subIndex = existingSubscribers?.findIndex(
+2 -11
View File
@@ -137,7 +137,7 @@ export default class EventBusService
): Promise<TResult | void> { ): Promise<TResult | void> {
const manager = this.activeManager_ const manager = this.activeManager_
const isBulkEmit = !isString(eventNameOrData) const isBulkEmit = !isString(eventNameOrData)
let events: EventBusTypes.EmitData[] = isBulkEmit const events: EventBusTypes.EmitData[] = isBulkEmit
? eventNameOrData.map((event) => ({ ? eventNameOrData.map((event) => ({
eventName: event.eventName, eventName: event.eventName,
data: event.data, data: event.data,
@@ -151,14 +151,6 @@ export default class EventBusService
}, },
] ]
events = events.filter(
(event) =>
this.eventBusModuleService_?.retrieveSubscribers(event.eventName)
?.length ?? false
)
let stagedJobs: StagedJob[] = []
if (events.length) {
/** /**
* We store events in the database when in an ongoing transaction. * We store events in the database when in an ongoing transaction.
* *
@@ -173,10 +165,9 @@ export default class EventBusService
* as part of the rollback. * as part of the rollback.
*/ */
stagedJobs = await this.stagedJobService_ const stagedJobs = await this.stagedJobService_
.withTransaction(manager) .withTransaction(manager)
.create(events) .create(events)
}
return (!isBulkEmit ? stagedJobs[0] : stagedJobs) as unknown as TResult return (!isBulkEmit ? stagedJobs[0] : stagedJobs) as unknown as TResult
} }
@@ -1,15 +1,6 @@
import { import { EmitData, Subscriber, SubscriberContext } from "./common"
EmitData,
Subscriber,
SubscriberContext,
SubscriberDescriptor,
} from "./common"
export interface IEventBusModuleService { export interface IEventBusModuleService {
retrieveSubscribers(
event: string | symbol
): SubscriberDescriptor[] | undefined
emit<T>( emit<T>(
eventName: string, eventName: string,
data: T, data: T,
+1 -5
View File
@@ -50,10 +50,6 @@ export abstract class AbstractEventBusModuleService
]) ])
} }
public retrieveSubscribers(event: string | symbol) {
return this.eventToSubscribersMap_.get(event)
}
public subscribe( public subscribe(
eventName: string | symbol, eventName: string | symbol,
subscriber: EventBusTypes.Subscriber, subscriber: EventBusTypes.Subscriber,
@@ -88,7 +84,7 @@ export abstract class AbstractEventBusModuleService
throw new Error("Subscriber must be a function") throw new Error("Subscriber must be a function")
} }
const existingSubscribers = this.retrieveSubscribers(eventName) const existingSubscribers = this.eventToSubscribersMap_.get(eventName)
if (existingSubscribers?.length) { if (existingSubscribers?.length) {
const subIndex = existingSubscribers?.findIndex( const subIndex = existingSubscribers?.findIndex(