REFACTOR: Import user visits from lithium database
This commit is contained in:
parent
e5c156b226
commit
750367007c
|
@ -70,6 +70,7 @@ class ImportScripts::Lithium < ImportScripts::Base
|
|||
import_groups
|
||||
import_categories
|
||||
import_users
|
||||
import_user_visits
|
||||
import_topics
|
||||
import_posts
|
||||
import_likes
|
||||
|
@ -159,20 +160,6 @@ class ImportScripts::Lithium < ImportScripts::Base
|
|||
post_create_action: proc do |u|
|
||||
@old_username_to_new_usernames[user["login_canon"]] = u.username
|
||||
|
||||
# import user visits
|
||||
visits = mysql_query <<-SQL
|
||||
SELECT login_time
|
||||
FROM user_log
|
||||
WHERE user_id = #{user_id}
|
||||
SQL
|
||||
|
||||
if visits.count > 0
|
||||
visits.each do |visit|
|
||||
date = unix_time(visit["login_time"]).to_date
|
||||
u.update_visit_record!(date)
|
||||
end
|
||||
end
|
||||
|
||||
# import user avatar
|
||||
sso_id = u.custom_fields["sso_id"]
|
||||
if sso_id.present?
|
||||
|
@ -200,6 +187,35 @@ class ImportScripts::Lithium < ImportScripts::Base
|
|||
end
|
||||
end
|
||||
|
||||
def import_user_visits
|
||||
puts "", "importing user visits"
|
||||
|
||||
batches(BATCH_SIZE) do |offset|
|
||||
visits = mysql_query <<-SQL
|
||||
SELECT user_id, login_time
|
||||
FROM user_log
|
||||
ORDER BY user_id
|
||||
LIMIT #{BATCH_SIZE}
|
||||
OFFSET #{offset}
|
||||
SQL
|
||||
|
||||
break if visits.size < 1
|
||||
|
||||
user_ids = visits.uniq { |v| v["user_id"] }
|
||||
|
||||
user_ids.each do |user_id|
|
||||
user = UserCustomField.find_by(name: "import_id", value: user_id).try(:user)
|
||||
raise "User not found for id #{user_id}" if user.blank?
|
||||
|
||||
user_visits = visits.select { |v| v["user_id"] == user_id }
|
||||
user_visits.each do |v|
|
||||
date = unix_time(v["login_time"])
|
||||
user.update_visit_record!(date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def user_custom_fields(user, profile)
|
||||
fields = Hash.new
|
||||
|
||||
|
|
Loading…
Reference in New Issue