diff options
author | Stan Hu <stanhu@gmail.com> | 2017-01-11 09:38:30 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-01-11 09:47:53 -0800 |
commit | 1e17096f5fb1c107f5a850dd5f64c89ced6c13fb (patch) | |
tree | b12b93a241b0ef9930ffa9fde54d4dcd5362f21e | |
parent | 1ff2dfa1cc6ba125ed53d42443713dcbda3f57f6 (diff) | |
download | gitlab-ce-sh-speed-up-get-all-versions-test.tar.gz |
Memoize `get_all_versions` to reduce number of DB queries in testssh-speed-up-get-all-versions-test
Every time we access `ApplicationSetting` (e.g. when creating a user), we
also run `ActiveRecord::Migrator.needs_migration`:
```ruby
def needs_migration?(connection = Base.connection)
(migrations(migrations_paths).collect(&:version) - get_all_versions(connection)).size > 0
end
```
During tests, we memoized the `migrations` call, saving a lot of filesystem
loads. However, we left `get_all_versions` alone. This patch memoizes that
as well to reduce DB and memory loads for that table.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/24899#note_21207429
-rw-r--r-- | config/initializers/ar_speed_up_migration_checking.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/config/initializers/ar_speed_up_migration_checking.rb b/config/initializers/ar_speed_up_migration_checking.rb index 1fe5defc01d..d61e2230b54 100644 --- a/config/initializers/ar_speed_up_migration_checking.rb +++ b/config/initializers/ar_speed_up_migration_checking.rb @@ -5,6 +5,7 @@ if Rails.env.test? class Migrator class << self alias_method :migrations_unmemoized, :migrations + alias_method :get_all_versions_unmemoized, :get_all_versions # 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 @@ -12,6 +13,10 @@ if Rails.env.test? def migrations(paths) @migrations ||= migrations_unmemoized(paths) end + + def get_all_versions(connection = Base.connection) + @all_versions ||= get_all_versions_unmemoized(connection) + end end end end |