mirror of
https://github.com/discourse/discourse.git
synced 2026-08-03 09:53:24 -05:00
Posts and chat messages with inline oneboxes to GitHub PRs were being
unnecessarily rebaked when the PR status changed. This happened because
the check `cooked.include?("onebox")` matched both full oneboxes
(`class="onebox githubpullrequest"`) and inline oneboxes
(`class="inline-onebox"`).
Changed the check to match "githubpullrequest" specifically, which only
appears in full PR oneboxes that actually display the status.
Internal ref - t/169442
53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class RebakeGithubPrPosts < ::Jobs::Base
|
|
sidekiq_options queue: "low"
|
|
|
|
def execute(args)
|
|
pr_url = args[:pr_url]
|
|
return if pr_url.blank?
|
|
|
|
rebake_posts(pr_url)
|
|
rebake_chat_messages(pr_url) if SiteSetting.chat_enabled
|
|
end
|
|
|
|
private
|
|
|
|
def rebake_posts(pr_url)
|
|
post_ids =
|
|
TopicLink
|
|
.where(url: pr_url)
|
|
.or(TopicLink.where("url LIKE ?", "#{pr_url}%"))
|
|
.select(:post_id)
|
|
|
|
Post
|
|
.where(id: post_ids)
|
|
.find_each do |post|
|
|
next unless has_github_pr_onebox?(post.cooked, pr_url)
|
|
post.rebake!(invalidate_oneboxes: true, priority: :low)
|
|
end
|
|
end
|
|
|
|
def rebake_chat_messages(pr_url)
|
|
message_ids =
|
|
::Chat::MessageLink
|
|
.where(url: pr_url)
|
|
.or(::Chat::MessageLink.where("url LIKE ?", "#{pr_url}%"))
|
|
.select(:chat_message_id)
|
|
|
|
::Chat::Message
|
|
.where(id: message_ids)
|
|
.find_each do |message|
|
|
next unless has_github_pr_onebox?(message.cooked, pr_url)
|
|
message.rebake!(invalidate_oneboxes: true, priority: :low)
|
|
end
|
|
end
|
|
|
|
def has_github_pr_onebox?(cooked, pr_url)
|
|
# quick & dirty check to avoid doing unnecessary rebakes
|
|
cooked.present? && cooked.include?("githubpullrequest") && cooked.include?(pr_url)
|
|
end
|
|
end
|
|
end
|