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
6f5b68c5
Commit
6f5b68c5
authored
Apr 11, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1983-geo-enabled-cache' into 'master'
Cache Gitlab::Geo queries Closes #1983 See merge request !1507
parents
1b88d48d
f2f0d6da
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
1 deletion
+49
-1
app/models/geo_node.rb
app/models/geo_node.rb
+6
-0
changelogs/unreleased-ee/1983-geo-enabled-cache.yml
changelogs/unreleased-ee/1983-geo-enabled-cache.yml
+4
-0
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+23
-1
spec/models/geo_node_spec.rb
spec/models/geo_node_spec.rb
+16
-0
No files found.
app/models/geo_node.rb
View file @
6f5b68c5
...
...
@@ -22,7 +22,9 @@ class GeoNode < ActiveRecord::Base
after_initialize
:build_dependents
after_save
:refresh_bulk_notify_worker_status
after_save
:expire_cache!
after_destroy
:refresh_bulk_notify_worker_status
after_destroy
:expire_cache!
before_validation
:update_dependents_attributes
before_validation
:ensure_access_keys!
...
...
@@ -160,4 +162,8 @@ class GeoNode < ActiveRecord::Base
self
.
system_hook
.
push_events
=
true
self
.
system_hook
.
tag_push_events
=
true
end
def
expire_cache!
Gitlab
::
Geo
.
expire_cache!
end
end
changelogs/unreleased-ee/1983-geo-enabled-cache.yml
0 → 100644
View file @
6f5b68c5
---
title
:
Cache Gitlab::Geo queries
merge_request
:
1507
author
:
lib/gitlab/geo.rb
View file @
6f5b68c5
...
...
@@ -2,6 +2,16 @@ module Gitlab
module
Geo
OauthApplicationUndefinedError
=
Class
.
new
(
StandardError
)
CACHE_KEYS
=
%i[
geo_primary_node
geo_secondary_nodes
geo_node_enabled
geo_node_primary
geo_node_secondary
geo_primary_ssh_path_prefix
geo_oauth_application
]
.
freeze
def
self
.
current_node
self
.
cache_value
(
:geo_node_current
)
do
GeoNode
.
find_by
(
host:
Gitlab
.
config
.
gitlab
.
host
,
...
...
@@ -80,7 +90,19 @@ module Gitlab
def
self
.
cache_value
(
key
,
&
block
)
return
yield
unless
RequestStore
.
active?
RequestStore
.
fetch
(
key
)
{
yield
}
# We need a short expire time as we can't manually expire on a secondary node
RequestStore
.
fetch
(
key
)
{
Rails
.
cache
.
fetch
(
key
,
expires_in:
15
.
seconds
)
{
yield
}
}
end
def
self
.
expire_cache!
return
true
unless
RequestStore
.
active?
CACHE_KEYS
.
each
do
|
key
|
Rails
.
cache
.
delete
(
key
)
RequestStore
.
delete
(
key
)
end
true
end
def
self
.
generate_access_keys
...
...
spec/models/geo_node_spec.rb
View file @
6f5b68c5
...
...
@@ -95,6 +95,22 @@ describe GeoNode, type: :model do
end
end
context
'cache expiration'
do
let
(
:new_node
)
{
FactoryGirl
.
build
(
:geo_node
)
}
it
'expires cache when saved'
do
expect
(
new_node
).
to
receive
(
:expire_cache!
)
new_node
.
save!
end
it
'expires cache when removed'
do
expect
(
node
).
to
receive
(
:expire_cache!
)
# 1 for creation 1 for deletion
node
.
destroy
end
end
describe
'#uri'
do
context
'when all fields are filled'
do
it
'returns an URI object'
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