v0.45 SQLIte mutexes only wrap around updates now

This commit is contained in:
David Sainty 2024-08-18 05:12:42 +10:00
parent 90a2d2fa37
commit 0372db9cc7

View File

@ -1,7 +1,7 @@
# Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- Migration-Import Script
# v0.44 Try removing connection_pool and starting MySQL within thread method and fix handle_post_attachment
# v0.45 SQLIte mutexes only wrap around updates now
require 'mysql2'
require 'open-uri'
@ -1311,9 +1311,9 @@ class GossamerForumsImporter < ImportScripts::Base
puts "CREATE TOPIC POST topic.id #{topic.id} discourse_user_id #{discourse_user_id}"
post_number = 0
# Increment the post count for the topic
post_number = fetch_db_topic_post_numbers(topic.id).to_i + 1
sqlite_mutex.synchronize do
# Increment the post count for the topic
post_number = fetch_db_topic_post_numbers(topic.id).to_i + 1
update_db_topic_post_numbers(topic.id, post_number)
end
@ -1361,28 +1361,28 @@ class GossamerForumsImporter < ImportScripts::Base
puts "CREATE REPLY in topic_id #{topic.id}"
# Increment the post count for the topic
post_number = fetch_db_topic_post_numbers(topic.id).to_i + 1
sqlite_mutex.synchronize do
# Increment the post count for the topic
post_number = fetch_db_topic_post_numbers(topic.id).to_i + 1
update_db_topic_post_numbers(topic.id, post_number)
end
# Fetch the number of views the post has had
reply_post_views = fetch_post_views(reply_row['post_id'])
# Fetch the number of views the post has had
reply_post_views = fetch_post_views(reply_row['post_id'])
puts "TIJ JJ post_id #{post_id}"
# Create the reply post in the existing topic
post = Post.create!(
topic_id: topic.id,
user_id: reply_user_id,
raw: sanitized_reply_message,
created_at: Time.at(reply_row['post_time']),
updated_at: Time.at(reply_row['post_time']),
reads: reply_post_views || 0,
post_number: post_number
)
post.custom_fields['original_gossamer_id'] = reply_row['post_id']
post.save!
end
# Create the reply post in the existing topic
post = Post.create!(
topic_id: topic.id,
user_id: reply_user_id,
raw: sanitized_reply_message,
created_at: Time.at(reply_row['post_time']),
updated_at: Time.at(reply_row['post_time']),
reads: reply_post_views || 0,
post_number: post_number
)
post.custom_fields['original_gossamer_id'] = reply_row['post_id']
post.save!
puts "TIJ KK post_id #{post_id}"
# Increment the post count for the topic and user