DEV: Publish DiscourseEvent after top topic period is calculated (#29142)

This commit is contained in:
Mark VanLandingham 2024-10-10 08:10:39 -05:00 committed by GitHub
parent 374238b910
commit 909264ee75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -212,6 +212,8 @@ class TopTopic < ActiveRecord::Base
SQL
DB.exec(sql, from: start_of(period))
DiscourseEvent.trigger(:top_score_computed, period: period)
end
def self.start_of(period)

View File

@ -152,5 +152,12 @@ RSpec.describe TopTopic do
0.0000000001,
).of(10.602059991328)
end
it "triggers a DiscourseEvent for each refreshed period" do
events = DiscourseEvent.track_events(:top_score_computed) { TopTopic.refresh! }
periods = events.map { |e| e[:params].first[:period] }
expect(periods).to match_array(%i[daily weekly monthly quarterly yearly all])
end
end
end