Preventing Ruby on Rails notification demo from sending the same information more than once
The part of the real estate application I am writing will allow the user to subscribe to a location, and if a new property becomes available in that location, the user will receive an email notifying this.
I plan to run a background process every few hours to process the match.
I now have a model called location and the plan is to add another model called notification. The location model has latitude and longitude and a notification model.
Sort of:
create_table "locations", :force => true do |t|
t.decimal "lat", :precision => 15, :scale => 10
t.decimal "lng", :precision => 15, :scale => 10
end
create_table "notifications", :force => true do |t|
t.decimal "lat", :precision => 15, :scale => 10
t.decimal "lng", :precision => 15, :scale => 10
t.string "user_name"
t.string "user_email"
end
The obvious thing to do is look at the list of locations, and if it matches that in the notification, then send an email to the user_email defined in the notification model.
What I'm trying to avoid is sending the same location email to the same user more than once. What works with the process every few hours.
I thought about adding another field to the notification model named "has_been_mailed", which will be set to true after mail is sent, but then that means no future updates of other added places will be received.
Does anyone have any suggestions as to the best way to implement this?
a source to share