vanilla_mysql faster users when resuming, create_permalinks

This commit is contained in:
Neil Lalonde 2016-05-17 11:16:41 -04:00
parent 3deda3ca39
commit e1061acd32
1 changed files with 40 additions and 0 deletions

View File

@ -27,6 +27,10 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
import_categories import_categories
import_topics import_topics
import_posts import_posts
update_tl0
create_permalinks
end end
def import_users def import_users
@ -54,6 +58,7 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
create_users(results, total: total_count, offset: offset) do |user| create_users(results, total: total_count, offset: offset) do |user|
next if user['Email'].blank? next if user['Email'].blank?
next if user['Name'].blank? next if user['Name'].blank?
next if @lookup.user_id_from_imported_user_id(user['UserID'])
if user['Name'] == '[Deleted User]' if user['Name'] == '[Deleted User]'
# EVERY deleted user record in Vanilla has the same username: [Deleted User] # EVERY deleted user record in Vanilla has the same username: [Deleted User]
@ -325,6 +330,41 @@ class ImportScripts::VanillaSQL < ImportScripts::Base
# @client.query(sql, cache_rows: false) #segfault: cache_rows: false causes segmentation fault # @client.query(sql, cache_rows: false) #segfault: cache_rows: false causes segmentation fault
end end
def create_permalinks
puts '', 'Creating redirects...', ''
User.find_each do |u|
ucf = u.custom_fields
if ucf && ucf["import_id"] && ucf["import_username"]
Permalink.create(
url: "profile/#{ucf['import_id']}/#{ucf['import_username']}",
external_url: "/users/#{u.username}"
)
end
end end
Post.find_each do |post|
pcf = post.custom_fields
if pcf && pcf["import_id"]
topic = post.topic
id = pcf["import_id"].split('#').last
if post.post_number == 1
slug = Slug.for(topic.title) # probably matches what vanilla would do...
Permalink.create(
url: "discussion/#{id}/#{slug}",
topic_id: topic.id
)
else
Permalink.create(
url: "discussion/comment/#{id}",
post_id: post.id
)
end
end
end
end
end
ImportScripts::VanillaSQL.new.perform ImportScripts::VanillaSQL.new.perform