Dynamic Triggers/Notifications

Hi All – Got a problem I am trying to think through.

I want to allow users to list specific criteria, then receive an e-mail if a new item is created matching that criteria. What’s the best way to go about this. My mind is going a little numb thinking about how to do this at scale efficiently. Simple example:

User 1: Wants to be notified every time a new product is released that is “red”, a “shirt” and between $20 - $30?

I only want the user to be notified once and immediately when a new item is created. Some users may have more or less criteria they want.

Thoughts?

Following. I am looking for something similar. (Bulk notifications to specific and/or all users depending on action on site) . I still haven’t found an efficient solution.

Been thinking on this, I may have a solution, but it may be painfully inefficient at scale. I am considering using a kind of reverse data filter approach. Every time a new product is added, I’d loop through the user set notifications to see if new product meets the criteria. If so, send e-mail.

For example, 3 different users, each want to be notified when a product posted meets the following criteria.

User 1: Notified when “Red” “Shirt” $20 - 30" is listed
User 2: Notified when “Pants” are listed
User 3: Notified when anything below $100 listed

Each of these notifications are stored in a collection. Every time a new product is posted, I would have to query all of the notifications, then run a for loop checking to see which if any meet the new product criteria.

For Example:

  • User posts new Item: $88 Pants
  • Then I’d query all User Notifications collection:

Then Loop through all notifications to see if all the criteria meets the new item:
For (let i=0, i < usernotifications.length, i++) {
if (Critera 1 is met,
tempItems.filter(item =>
);
}
Repeater if for all criteria…
If item meets all criteria, then send e-mail to user.
}

Just spit balling ideas. I’ll psot final code when I build it. However, if anyone has improvements please let me know.

Thanks