FIX: Use a mutex when reseting column information while seeding.

`rake multisite:migrate` runs SeedFu concurently in threads so we need
this to be thread safe.
This commit is contained in:
Guo Xiang Tan 2020-06-23 09:15:29 +08:00
parent 0384b6d910
commit d775338d63
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
1 changed files with 12 additions and 7 deletions

View File

@ -1,17 +1,22 @@
# frozen_string_literal: true
class SeedData::Refresher
@mutex = Mutex.new
def self.refresh!
return if @refreshed
# Fix any bust caches post initial migration
# Not that reset_column_information is not thread safe so we have to becareful
# not to run it concurrently within the same process.
ActiveRecord::Base.connection.tables.each do |table|
table.classify.constantize.reset_column_information rescue nil
end
@mutex.synchronize do
return if @refreshed
# Fix any bust caches post initial migration
# Not that reset_column_information is not thread safe so we have to becareful
# not to run it concurrently within the same process.
ActiveRecord::Base.connection.tables.each do |table|
table.classify.constantize.reset_column_information rescue nil
end
@refreshed = true
@refreshed = true
end
end
end