summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-10-07 01:26:05 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-10-07 01:26:05 +0000
commit4a90e25f0308515bc4f240e82854a364aea47046 (patch)
treee63f2c966d4dc7a9286916773e8e892f72bf0534
parent8068d3e164800cdc0c61195009f1e6fc02e796d1 (diff)
parent5766e0661dd39198bdafeb53678830df4c3c5e3e (diff)
downloadgitlab-ce-4a90e25f0308515bc4f240e82854a364aea47046.tar.gz
Merge branch '23034-memoize-ar-migrator-migrations-in-tests' into 'master'
Memoize ActiveRecord::Migrator.migrations in tests See merge request !6723
-rw-r--r--config/initializers/ar_speed_up_migration_checking.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/config/initializers/ar_speed_up_migration_checking.rb b/config/initializers/ar_speed_up_migration_checking.rb
new file mode 100644
index 00000000000..1fe5defc01d
--- /dev/null
+++ b/config/initializers/ar_speed_up_migration_checking.rb
@@ -0,0 +1,18 @@
+if Rails.env.test?
+ require 'active_record/migration'
+
+ module ActiveRecord
+ class Migrator
+ class << self
+ alias_method :migrations_unmemoized, :migrations
+
+ # This method is called a large number of times per rspec example, and
+ # it reads + parses `db/migrate/*` each time. Memoizing it can save 0.5
+ # seconds per spec.
+ def migrations(paths)
+ @migrations ||= migrations_unmemoized(paths)
+ end
+ end
+ end
+ end
+end