FIX: Reset last sent for existent bookmarks (#16202)
The meaning of reminder_at and reminder_last_sent_at changed after
commit 6d422a8033
. A bookmark reminder
will fire only if reminder_last_sent_at is null, but before that it
fired everytime reminder_at was set. This is no longer true because
sometimes reminder_at continues to exist even after a reminder fired.
This commit is contained in:
parent
13b4b0d3c4
commit
30f3e78834
|
@ -18,7 +18,7 @@ module Jobs
|
|||
end
|
||||
|
||||
def execute(args = nil)
|
||||
bookmarks = Bookmark.pending_reminders.includes(:user).where(reminder_last_sent_at: nil).order('reminder_at ASC')
|
||||
bookmarks = Bookmark.pending_reminders.includes(:user).order('reminder_at ASC')
|
||||
bookmarks.limit(BookmarkReminderNotifications.max_reminder_notifications_per_run).each do |bookmark|
|
||||
BookmarkReminderNotificationHandler.send_notification(bookmark)
|
||||
end
|
||||
|
|
|
@ -112,7 +112,7 @@ class Bookmark < ActiveRecord::Base
|
|||
end
|
||||
|
||||
scope :pending_reminders, ->(before_time = Time.now.utc) do
|
||||
with_reminders.where("reminder_at <= :before_time", before_time: before_time)
|
||||
with_reminders.where("reminder_at <= ?", before_time).where(reminder_last_sent_at: nil)
|
||||
end
|
||||
|
||||
scope :pending_reminders_for_user, ->(user) do
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ResetBookmarksReminderLastSentAt < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
DB.exec <<~SQL
|
||||
UPDATE bookmarks
|
||||
SET reminder_last_sent_at = NULL
|
||||
WHERE reminder_last_sent_at < reminder_at
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue