v0.52 Improve handling and look at how we can improve ActiveRecord config for PostgreSQL and avoid insufficient pool size
This commit is contained in:
parent
bcc7519d78
commit
5735b78dc7
@ -1090,7 +1090,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Use CachedThreadPool for dynamic thread management
|
# Use CachedThreadPool for dynamic thread management
|
||||||
#### pool = Concurrent::CachedThreadPool.new
|
#### pool = Concurrent::CachedThreadPool.new
|
||||||
###### pool = Concurrent::FixedThreadPool.new(7)
|
###### pool = Concurrent::FixedThreadPool.new(7)
|
||||||
pool = Concurrent::FixedThreadPool.new(20)
|
pool = Concurrent::FixedThreadPool.new(7)
|
||||||
|
|
||||||
# Define the connection pool inside the method
|
# Define the connection pool inside the method
|
||||||
###### mariadb_pool = ConnectionPool.new(size: 14, timeout: 100) do
|
###### mariadb_pool = ConnectionPool.new(size: 14, timeout: 100) do
|
||||||
@ -1157,7 +1157,8 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Submit the import job for the current post_id to the thread pool
|
# Submit the import job for the current post_id to the thread pool
|
||||||
pool.post do
|
pool.post do
|
||||||
#### puts "PP 22 -- #{post_id}"
|
#### puts "PP 22 -- #{post_id}"
|
||||||
|
|
||||||
|
retries = 0
|
||||||
begin
|
begin
|
||||||
####### mariadb_pool.with do |mysql_client|
|
####### mariadb_pool.with do |mysql_client|
|
||||||
|
|
||||||
@ -1209,7 +1210,6 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
when /MySQL client is not connected/, /This connection is in use by/
|
when /MySQL client is not connected/, /This connection is in use by/
|
||||||
puts "Lost MySQL, retrying for post ID #{post_id}..."
|
puts "Lost MySQL, retrying for post ID #{post_id}..."
|
||||||
# Add reconnection attempt again here... if it proves necessary?
|
# Add reconnection attempt again here... if it proves necessary?
|
||||||
retries ||= 0
|
|
||||||
retries += 1
|
retries += 1
|
||||||
if retries < 5
|
if retries < 5
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@ -1219,7 +1219,6 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
when /could not obtain a connection from the pool/
|
when /could not obtain a connection from the pool/
|
||||||
puts "Connection pool exhausted, retrying for post ID #{post_id}..."
|
puts "Connection pool exhausted, retrying for post ID #{post_id}..."
|
||||||
retries ||= 0
|
|
||||||
retries += 1
|
retries += 1
|
||||||
if retries < 5
|
if retries < 5
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@ -1326,13 +1325,13 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Check if the topic has already been imported using the custom field 'original_gossamer_id'
|
# Check if the topic has already been imported using the custom field 'original_gossamer_id'
|
||||||
unless TopicCustomField.exists?(name: 'original_gossamer_id', value: row['post_id'])
|
unless TopicCustomField.exists?(name: 'original_gossamer_id', value: row['post_id'])
|
||||||
puts "TIJ EE post_id #{post_id}"
|
puts "TIJ EE post_id #{post_id}"
|
||||||
# ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
# Create the new topic in Discourse
|
# Create the new topic in Discourse
|
||||||
begin
|
begin
|
||||||
suffix = 1
|
suffix = 1
|
||||||
topic_created = false
|
topic_created = false
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
## ActiveRecord::Base.transaction do
|
||||||
while !topic_created
|
while !topic_created
|
||||||
begin
|
begin
|
||||||
puts "TIJ FF post_id #{post_id}"
|
puts "TIJ FF post_id #{post_id}"
|
||||||
@ -1361,7 +1360,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# puts e.backtrace.join("\n") # Print the full stack trace
|
# puts e.backtrace.join("\n") # Print the full stack trace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
## end
|
||||||
|
|
||||||
# Workaround... take a copy of topic.id
|
# Workaround... take a copy of topic.id
|
||||||
current_topic_id = topic.id
|
current_topic_id = topic.id
|
||||||
@ -1389,7 +1388,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
puts "TIJ GG post_id #{post_id}"
|
puts "TIJ GG post_id #{post_id}"
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
## ActiveRecord::Base.transaction do
|
||||||
# Create the initial post in the new topic
|
# Create the initial post in the new topic
|
||||||
post = Post.create!(
|
post = Post.create!(
|
||||||
topic_id: current_topic_id,
|
topic_id: current_topic_id,
|
||||||
@ -1402,7 +1401,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
)
|
)
|
||||||
post.custom_fields['original_gossamer_id'] = row['post_id']
|
post.custom_fields['original_gossamer_id'] = row['post_id']
|
||||||
post.save!
|
post.save!
|
||||||
end
|
## end
|
||||||
|
|
||||||
sqlite_mutex.synchronize do
|
sqlite_mutex.synchronize do
|
||||||
# Increment the post count for the topic and user
|
# Increment the post count for the topic and user
|
||||||
@ -1412,10 +1411,10 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
puts "TIJ HH post_id #{post_id}"
|
puts "TIJ HH post_id #{post_id}"
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
## ActiveRecord::Base.transaction do
|
||||||
# Handle any attachments associated with the post
|
# Handle any attachments associated with the post
|
||||||
handle_post_attachments(row['post_id'], post, discourse_user_id, mysql_client)
|
handle_post_attachments(row['post_id'], post, discourse_user_id, mysql_client)
|
||||||
end
|
## end
|
||||||
|
|
||||||
# Create URL mappings for the new topic
|
# Create URL mappings for the new topic
|
||||||
new_url = "https://new/t/#{topic.slug}/#{current_topic_id}"
|
new_url = "https://new/t/#{topic.slug}/#{current_topic_id}"
|
||||||
@ -1464,7 +1463,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
puts "TIJ JJ post_id #{post_id} reply post_id #{reply_row['post_id']} reply_post_views #{reply_post_views || 0} post_number #{post_number} current_topic_id #{current_topic_id} reply_post_views #{reply_post_views || 0}"
|
puts "TIJ JJ post_id #{post_id} reply post_id #{reply_row['post_id']} reply_post_views #{reply_post_views || 0} post_number #{post_number} current_topic_id #{current_topic_id} reply_post_views #{reply_post_views || 0}"
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
## ActiveRecord::Base.transaction do
|
||||||
# Create the reply post in the existing topic
|
# Create the reply post in the existing topic
|
||||||
post = Post.create!(
|
post = Post.create!(
|
||||||
topic_id: current_topic_id,
|
topic_id: current_topic_id,
|
||||||
@ -1477,7 +1476,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
)
|
)
|
||||||
post.custom_fields['original_gossamer_id'] = reply_row['post_id']
|
post.custom_fields['original_gossamer_id'] = reply_row['post_id']
|
||||||
post.save!
|
post.save!
|
||||||
end
|
## end
|
||||||
|
|
||||||
puts "TIJ KK post_id #{post_id}"
|
puts "TIJ KK post_id #{post_id}"
|
||||||
# Increment the post count for the topic and user
|
# Increment the post count for the topic and user
|
||||||
@ -1494,10 +1493,10 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
## ActiveRecord::Base.transaction do
|
||||||
# Handle any attachments associated with the reply
|
# Handle any attachments associated with the reply
|
||||||
handle_post_attachments(reply_row['post_id'], post, reply_user_id, mysql_client)
|
handle_post_attachments(reply_row['post_id'], post, reply_user_id, mysql_client)
|
||||||
end
|
## end
|
||||||
|
|
||||||
# # Update the highest processed post_id in the database (thread-safe)
|
# # Update the highest processed post_id in the database (thread-safe)
|
||||||
# update_highest_processed_post_id_thread_safe(reply_row['post_id'])
|
# update_highest_processed_post_id_thread_safe(reply_row['post_id'])
|
||||||
@ -1516,7 +1515,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
puts "---> ERROR importing topic with post_id #{row['post_id']}: #{e.message}"
|
puts "---> ERROR importing topic with post_id #{row['post_id']}: #{e.message}"
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
# end
|
end
|
||||||
else
|
else
|
||||||
puts "Topic for post_id #{row['post_id']} already exists, skipping creation."
|
puts "Topic for post_id #{row['post_id']} already exists, skipping creation."
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user