mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 13:03:43 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
29 lines
696 B
Ruby
29 lines
696 B
Ruby
# frozen_string_literal: true
|
|
|
|
class FixLinkPostId < ActiveRecord::Migration[4.2]
|
|
def up
|
|
to_remove = []
|
|
|
|
TopicLink.where('internal = TRUE AND link_post_id IS NULL').each do |tl|
|
|
|
|
begin
|
|
parsed = URI.parse(tl.url)
|
|
route = Rails.application.routes.recognize_path(parsed.path)
|
|
if route[:topic_id].present?
|
|
post = Post.find_by(topic_id: route[:topic_id], post_number: (route[:post_number] || 1))
|
|
tl.update_column(:link_post_id, post.id) if post.present?
|
|
end
|
|
|
|
rescue ActionController::RoutingError
|
|
to_remove << tl.id
|
|
end
|
|
|
|
end
|
|
|
|
TopicLink.where("id in (?)", to_remove).delete_all
|
|
end
|
|
|
|
def down
|
|
end
|
|
end
|