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:
Bianca Nenciu 2022-03-18 16:31:35 +02:00 committed by GitHub
parent 13b4b0d3c4
commit 30f3e78834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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