v0.60 Final tweak for topic and user count updating for last public posts

This commit is contained in:
David Sainty 2024-09-02 17:36:55 +10:00
parent bd119a3000
commit 9f6f71d197

View File

@ -1926,6 +1926,48 @@ class GossamerForumsImporter < ImportScripts::Base
end end
end end
def update_user_stats_finalfinal
@db.execute("SELECT * FROM user_post_count_final").each do |row|
user_id, count = row
puts "update_user_stats user_id #{user_id}"
begin
user_stat = UserStat.find_or_initialize_by(user_id: user_id)
# Fetch the current post count for the user
post_count = user_stat.post_count.to_i
## user_stat.update_columns(post_count: new_post_count)
# Fetch the current user and check if Trust Level needs updating
new_trust_level = case post_count
when 0..29 then 1 # basic user
else 2 # member, regular reserved for now.
# when 3..50 then 2 # member
# else 3 # regular or above when 51..100
end
user = User.find(user_id)
current_trust_level = user.trust_level
if user.id = 2
puts "USER ID 2, so TRUST LEVEL 4"
new_trust_level = 4
end
# Only update trust level if the new level is higher than the current one
if new_trust_level != current_trust_level
user.update!(trust_level: new_trust_level)
puts "update_user_stats user_id #{user_id} trust_level was #{current_trust_level}, now updated to #{new_trust_level}"
else
puts "update_user_stats user_id #{user_id} trust_level remains at #{current_trust_level}"
end
rescue
puts "WARNING: Could not find or modify User with id=#{user_id}. Skipping..."
end
end
end
def update_user_stats_final def update_user_stats_final
# Update user profiles with the number of topics and posts created # Update user profiles with the number of topics and posts created
puts "Update user profiles with the number of topics and posts created" puts "Update user profiles with the number of topics and posts created"
@ -2160,14 +2202,14 @@ class GossamerForumsImporter < ImportScripts::Base
### import_categories ### import_categories
## import_topics_and_posts ### import_topics_and_posts
# threaded_topic_import ### threaded_topic_import
#### update_topic_stats ### update_topic_stats
#### update_user_stats ### update_user_stats
update_topic_stats_final ### update_topic_stats_final
update_user_stats_final update_user_stats_finalfinal
### export_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}") ### export_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}")
### export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf") ### export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf")