Use Announcement scopes in scheduled status scheduler

This commit is contained in:
Matt Jankowski 2024-09-06 16:16:09 -04:00
parent cfb8fc6222
commit 409a29befd
2 changed files with 10 additions and 2 deletions

View File

@ -22,6 +22,10 @@ class Announcement < ApplicationRecord
scope :published, -> { where(published: true) }
scope :chronological, -> { order(coalesced_chronology_timestamps.asc) }
scope :reverse_chronological, -> { order(coalesced_chronology_timestamps.desc) }
scope :ending_before, ->(date) { ending.where(ends_at: ..date) }
scope :ending, -> { where.not(ends_at: nil) }
scope :scheduled_before, ->(date) { scheduled.where(scheduled_at: ..date) }
scope :scheduled, -> { where.not(scheduled_at: nil) }
has_many :announcement_mutes, dependent: :destroy
has_many :announcement_reactions, dependent: :destroy

View File

@ -30,7 +30,7 @@ class Scheduler::ScheduledStatusesScheduler
end
def due_announcements
Announcement.unpublished.where('scheduled_at IS NOT NULL AND scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
Announcement.unpublished.scheduled_before(publication_scheduled_at)
end
def unpublish_expired_announcements!
@ -38,6 +38,10 @@ class Scheduler::ScheduledStatusesScheduler
end
def expired_announcements
Announcement.published.where('ends_at IS NOT NULL AND ends_at <= ?', Time.now.utc)
Announcement.published.ending_before(Time.now.utc)
end
def publication_scheduled_at
Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET
end
end