Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
272783be
Commit
272783be
authored
Mar 15, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache table_exists?('application_settings') to reduce repeated schema reloads
Closes #43355
parent
4acbc941
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
1 deletion
+23
-1
changelogs/unreleased/sh-cache-table-exists.yml
changelogs/unreleased/sh-cache-table-exists.yml
+5
-0
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+1
-1
lib/gitlab/database.rb
lib/gitlab/database.rb
+5
-0
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+12
-0
No files found.
changelogs/unreleased/sh-cache-table-exists.yml
0 → 100644
View file @
272783be
---
title
:
Cache table_exists?('application_settings') to reduce repeated schema reloads
merge_request
:
author
:
type
:
performance
lib/gitlab/current_settings.rb
View file @
272783be
...
@@ -70,7 +70,7 @@ module Gitlab
...
@@ -70,7 +70,7 @@ module Gitlab
active_db_connection
=
ActiveRecord
::
Base
.
connection
.
active?
rescue
false
active_db_connection
=
ActiveRecord
::
Base
.
connection
.
active?
rescue
false
active_db_connection
&&
active_db_connection
&&
ActiveRecord
::
Base
.
connection
.
table_exists?
(
'application_settings'
)
Gitlab
::
Database
.
cached_
table_exists?
(
'application_settings'
)
rescue
ActiveRecord
::
NoDatabaseError
rescue
ActiveRecord
::
NoDatabaseError
false
false
end
end
...
...
lib/gitlab/database.rb
View file @
272783be
...
@@ -187,6 +187,11 @@ module Gitlab
...
@@ -187,6 +187,11 @@ module Gitlab
connection
.
schema_cache
.
columns_hash
(
table_name
).
has_key?
(
column_name
.
to_s
)
connection
.
schema_cache
.
columns_hash
(
table_name
).
has_key?
(
column_name
.
to_s
)
end
end
def
self
.
cached_table_exists?
(
table_name
)
# Rails 5 uses data_source_exists? instead of table_exists?
connection
.
schema_cache
.
table_exists?
(
table_name
)
end
private_class_method
:connection
private_class_method
:connection
def
self
.
database_version
def
self
.
database_version
...
...
spec/lib/gitlab/database_spec.rb
View file @
272783be
...
@@ -298,6 +298,18 @@ describe Gitlab::Database do
...
@@ -298,6 +298,18 @@ describe Gitlab::Database do
end
end
end
end
describe
'.cached_table_exists?'
do
it
'only retrieves data once per table'
do
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
with
(
:projects
).
once
.
and_call_original
expect
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
with
(
:bogus_table_name
).
once
.
and_call_original
2
.
times
do
expect
(
described_class
.
cached_table_exists?
(
:projects
)).
to
be_truthy
expect
(
described_class
.
cached_table_exists?
(
:bogus_table_name
)).
to
be_falsey
end
end
end
describe
'#true_value'
do
describe
'#true_value'
do
it
'returns correct value for PostgreSQL'
do
it
'returns correct value for PostgreSQL'
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment