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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
84a80a98
Commit
84a80a98
authored
Feb 07, 2017
by
Ruben Davila
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into ce-to-ee
parents
0da213c9
0150b04f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
7 deletions
+35
-7
changelogs/unreleased-ee/sh-fix-geo-node-cache.yml
changelogs/unreleased-ee/sh-fix-geo-node-cache.yml
+4
-0
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+14
-7
spec/lib/gitlab/geo_spec.rb
spec/lib/gitlab/geo_spec.rb
+17
-0
No files found.
changelogs/unreleased-ee/sh-fix-geo-node-cache.yml
0 → 100644
View file @
84a80a98
---
title
:
Reduce queries needed to check if node is a primary or secondary Geo node
merge_request
:
author
:
lib/gitlab/geo.rb
View file @
84a80a98
...
...
@@ -3,7 +3,7 @@ module Gitlab
class
OauthApplicationUndefinedError
<
StandardError
;
end
def
self
.
current_node
RequestStore
.
store
[
:geo_node_current
]
||=
begin
self
.
cache_value
(
:geo_node_current
)
do
GeoNode
.
find_by
(
host:
Gitlab
.
config
.
gitlab
.
host
,
port:
Gitlab
.
config
.
gitlab
.
port
,
relative_url_root:
Gitlab
.
config
.
gitlab
.
relative_url_root
)
...
...
@@ -11,15 +11,15 @@ module Gitlab
end
def
self
.
primary_node
RequestStore
.
store
[
:geo_primary_node
]
||=
GeoNode
.
find_by
(
primary:
true
)
self
.
cache_value
(
:geo_primary_node
)
{
GeoNode
.
find_by
(
primary:
true
)
}
end
def
self
.
secondary_nodes
RequestStore
.
store
[
:geo_secondary_nodes
]
||=
GeoNode
.
where
(
primary:
false
)
self
.
cache_value
(
:geo_secondary_nodes
)
{
GeoNode
.
where
(
primary:
false
)
}
end
def
self
.
enabled?
RequestStore
.
store
[
:geo_node_enabled
]
||=
GeoNode
.
exists?
self
.
cache_value
(
:geo_node_enabled
)
{
GeoNode
.
exists?
}
end
def
self
.
license_allows?
...
...
@@ -27,11 +27,11 @@ module Gitlab
end
def
self
.
primary?
RequestStore
.
store
[
:geo_node_primary?
]
||=
self
.
enabled?
&&
self
.
current_node
&&
self
.
current_node
.
primary?
self
.
cache_value
(
:geo_node_primary
)
{
self
.
enabled?
&&
self
.
current_node
&&
self
.
current_node
.
primary?
}
end
def
self
.
secondary?
RequestStore
.
store
[
:geo_node_secondary
]
||=
self
.
enabled?
&&
self
.
current_node
&&
!
self
.
current_node
.
primary?
self
.
cache_value
(
:geo_node_secondary
)
{
self
.
enabled?
&&
self
.
current_node
&&
!
self
.
current_node
.
primary?
}
end
def
self
.
geo_node?
(
host
:,
port
:)
...
...
@@ -49,8 +49,15 @@ module Gitlab
def
self
.
oauth_authentication
return
false
unless
Gitlab
::
Geo
.
secondary?
RequestStore
.
store
[
:geo_oauth_application
]
||=
self
.
cache_value
(
:geo_oauth_application
)
do
Gitlab
::
Geo
.
current_node
.
oauth_application
or
raise
OauthApplicationUndefinedError
end
end
def
self
.
cache_value
(
key
,
&
block
)
return
yield
unless
RequestStore
.
active?
RequestStore
.
fetch
(
key
)
{
yield
}
end
end
end
spec/lib/gitlab/geo_spec.rb
View file @
84a80a98
...
...
@@ -37,6 +37,23 @@ describe Gitlab::Geo, lib: true do
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
context
'with RequestStore enabled'
do
before
do
RequestStore
.
begin!
end
after
do
RequestStore
.
end!
RequestStore
.
clear!
end
it
'return false when no GeoNode exists'
do
expect
(
GeoNode
).
to
receive
(
:exists?
).
once
.
and_call_original
2
.
times
{
expect
(
described_class
.
enabled?
).
to
be_falsey
}
end
end
end
describe
'readonly?'
do
...
...
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