Skip to content

Memoize `get_all_versions to reduce` number of DB queries in tests

Stan Hu requested to merge sh-speed-up-get-all-versions-test into master

Memoize get_all_versions to reduce number of DB queries in tests

Every time we access ApplicationSetting (e.g. when creating a user), we also run ActiveRecord::Migrator.needs_migration:

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

Merge request reports