A platform for community discussion. Free, open, simple.
FIX: Use a mutex when reseting column information while seeding.
Guo Xiang Tand775338d637d
diff --git a/db/fixtures/001_refresh.rb b/db/fixtures/001_refresh.rbindex e340c8dfb0b..514789616dc 100644--- a/db/fixtures/001_refresh.rb+++ b/db/fixtures/001_refresh.rb@@ -1,17 +1,22 @@# frozen_string_literal: trueclass 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+ endendend