Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod to track price drops for a product on a user's wishlist?
    primarykey
    data
    text
    <p>Let's say I have these tables/models:</p> <pre><code>Product - id - last_updated_date - name - price User - id - name WishlistItem - id - user_id - product_id </code></pre> <p>The Product table has a few million records and is being updated automatically each night via a data import (inserting into a new table, dropping the old one). I basically have read-only access to that table/model.</p> <p>If a product is on a user's wishlist and the price drops, I'd like to be able to notify that user. What methods can be used to do this?</p> <p>I have a couple of ideas:</p> <ol> <li><p>Keep track of the Product.last_updated_date in the wishlist model and periodically poll the product table to see if it has been updated. This sounds like a horrible/non-scaleable solution.</p></li> <li><p>Some sort of Postgres View or Function that triggers when the Product table is updated? I'm new to postgres so I'm not yet sure if this is even possible.</p></li> <li><p>Something amazing that you will suggest that I haven't thought of :)</p></li> </ol> <p>Any help in the right direction is greatly appreciated!</p> <hr> <p>UPDATE: One idea that came up was caching the current price inside the wishlist entry itself, ie:</p> <pre><code>WishlistItem - id - user_id - product_id - price </code></pre> <p>... then, after the import, I could compare WishlistItem.price with Product.price and notify accordingly. Although it would work, this approach seems a bit wasteful since every WishlistItem for every user will essentially have the same cached copy of the price data and I'll have to update every list with the new price if there's an update. I'm not sure there's a way around it though.</p> <hr> <p>UPDATE: In the end I decided I should probably just be tracking all versions of the data so that I can use standard on update triggers. This also allows me to have a record of all price changes so I can track pricing trends, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload