I am working with some products and their discounts. The product creator can set the time and activate it whenever they like.
Example of the products and its fields:
Products =
[
{ name: 'P1', price: 10.00, discount: 5.00, timeLeftSeconds: 180, activeDiscount: false },
{ name: 'P2', price: 5.00, discount: 2.00, timeLeftSeconds: 200, activeDiscount: false },
{ name: 'P3', price: 15.00, discount: 7.50, timeLeftSeconds: 250, activeDiscount: false }
];
The customer can see a list of products with their normal price, if the discount is active, its countdown is displayed.
My first approach was to create a 1 second time interval that calls up the information of all the products of a creator, to know if the discount is active, as well as deactivate it when the time reaches 0 in the respective product.
This interval is created on the creator's page (so they know that the product has the discount activated and how much time is left) and on the page that lists the products for the customer.
You can then assume that every second, the database is called twice to obtain the list of products (1 for the creator page and another for the client list), plus the n calls to update the timeLeft when a discounts is active, which affects performance.
What I'm looking for is that once the creator updates a product on his personal page, the creator's pages and the list for the client, Countdowns start or deactivate depending on the product data.