#Minimizing redundancy in Observer pattern

8 messages · Page 1 of 1 (latest)

surreal osprey
#

I have an event called IncidentCreated which takes in the incident id. There are two event listeners using the OnEvent decorator. Both of these will need to fetch the Team that is connected to this incident. Since I am going to be adding many more event listeners in the future for this same event, and all of them will probably need to fetch the Team. How would guys go about eliminating the duplicate queries and making this setup more performant? I considered adding the team object to the event itself, but it feels like the event shouldn't have anything to do with that (or should it?).

Just curious how you guys might approach this. Thanks!

gritty rain
surreal osprey
#

@gritty rain I was going the cache route but it seemed overkill

#

I am thinking to create a sort of a middleman that listens to the event. instead of multiple event listeners, I can have 1 event listener and have it call multiple services I guess. Not the best I know lol

gritty rain
#

Another lazy approach would be enabling the in-memory query results caching option on the database module, which will break if you switch to a new db module without such a feature.

surreal osprey
#

@gritty rain Nice, I think typeorm has that

gritty rain
#

Yeap it does

surreal osprey
#

Alright thanks mate 🙏