Read about our upcoming Code of Conduct on this issue

Commit bdb20037 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'memoize-database-version' into 'master'

Memoize Gitlab::Database.version

See merge request gitlab-org/gitlab-ce!19021
---
title: Memoize Gitlab::Database.version
merge_request:
author:
type: performance
......@@ -43,7 +43,7 @@ def self.read_write?
end
def self.version
database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
@version ||= database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
end
def self.join_lateral_supported?
......
......@@ -32,6 +32,12 @@
end
describe '.version' do
around do |example|
described_class.instance_variable_set(:@version, nil)
example.run
described_class.instance_variable_set(:@version, nil)
end
context "on mysql" do
it "extracts the version number" do
allow(described_class).to receive(:database_version)
......@@ -49,6 +55,14 @@
expect(described_class.version).to eq '9.4.4'
end
end
it 'memoizes the result' do
count = ActiveRecord::QueryRecorder
.new { 2.times { described_class.version } }
.count
expect(count).to eq(1)
end
end
describe '.join_lateral_supported?' do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment