useplunk / plunk

The Open-Source Email Platform
https://www.useplunk.com
GNU Affero General Public License v3.0
2.95k stars 136 forks source link

fix: refetch contact after awaiting triggers #82

Closed nik-lampe closed 1 month ago

nik-lampe commented 1 month ago

This refetches the contact after triggers ran, so that marketing templates can be sent on actions triggered by the subscribe event. Otherwise the subscribe flag might still be false, because the contact has just subscribed and the entity is in a stale state and thus the template is not sent.

driaug commented 1 month ago

Refetching the contact on every event trigger is quite costly on the database.

I suggest we move this to the contacts controller's subscribe and unsubscribe routes! Try to use the ContactService.id() method after clearing the Redis key for the contact as this function will automatically cache the updated value as well!

https://github.com/useplunk/plunk/blob/3f70be95dde80c04611089f66b1fcaa8eb30655e/packages/api/src/controllers/v1/Contacts.ts#L93-L193

nik-lampe commented 1 month ago

Good point. I have updated the PR. The contact passed to the action service is now the updated object returned from the update call.

driaug commented 1 month ago

Looks great!

Please upgrade the version in the main package.json to 1.0.5 and I will merge it in for you.

Thank you for your contribution :)

nik-lampe commented 1 month ago

Done 👍