From e052d0c939c697669583ccb8c43d1130d2e4b7e4 Mon Sep 17 00:00:00 2001 From: saint Date: Thu, 4 Jul 2024 23:46:40 +1000 Subject: [PATCH] v0.27.2 Improvement for user stat handling --- gossamer_forums.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 42b05d8..37e8919 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,5 +1,5 @@ # gossamer threads migration-import code -# v0.27.1 +# v0.27.2 require 'mysql2' require 'open-uri' @@ -1084,7 +1084,7 @@ class GossamerForumsImporter < ImportScripts::Base puts "Importing topics and posts with attachments... Done." end - def update_topic_and_user_stats + def update_topic_stats # Update topics with the correct last post time, post count, and last post user puts "Update topics with the correct last post time, post count, and last post user" # topic_last_post_time.each do |topic_id, last_post_time| @@ -1110,7 +1110,9 @@ class GossamerForumsImporter < ImportScripts::Base last_post_user_id: fetch_db_topic_last_post_user(topic_id).to_i ) end + end + def update_user_stats # Update user profiles with the number of topics and posts created puts "Update user profiles with the number of topics and posts created" # user_topic_count.each do |user_id, count| @@ -1123,14 +1125,18 @@ class GossamerForumsImporter < ImportScripts::Base # end @db.execute("SELECT * FROM user_topic_count").each do |row| user_id, count = row - user = User.find(user_id) - user.update!(topic_count: count) +# user = User.find(user_id) +# user.update!(topic_count: count) + user_stat = UserStat.find_or_initialize_by(user_id: user_id) + user_stat.update_columns(topic_count: count) end @db.execute("SELECT * FROM user_post_count").each do |row| user_id, count = row - user = User.find(user_id) - user.update!(post_count: count) +# user = User.find(user_id) +# user.update!(post_count: count) + user_stat = UserStat.find_or_initialize_by(user_id: user_id) + user_stat.update_columns(post_count: count) end end @@ -1213,7 +1219,8 @@ class GossamerForumsImporter < ImportScripts::Base # import_categories # import_topics_and_posts_with_attachments - update_topic_and_user_stats +# update_topic_stats + update_user_stats export_url_mapping_to_csv("gossamer-migration-url-mapping#{timestamp}") create_nginx_rewrite_rules("gossamer-redirects#{timestamp}.conf")