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
Léo-Paul Géneau
gitlab-ce
Commits
8783c134
Commit
8783c134
authored
Oct 19, 2017
by
Kamil Trzcinski
Committed by
Winnie Hellmann
Oct 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent ApplicationSetting to cache nil value
parent
1bba9700
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
1 deletion
+24
-1
app/models/application_setting.rb
app/models/application_setting.rb
+4
-1
changelogs/unreleased/fix-application-setting-nil-cache.yml
changelogs/unreleased/fix-application-setting-nil-cache.yml
+5
-0
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+15
-0
No files found.
app/models/application_setting.rb
View file @
8783c134
...
...
@@ -203,7 +203,10 @@ class ApplicationSetting < ActiveRecord::Base
ensure_cache_setup
Rails
.
cache
.
fetch
(
CACHE_KEY
)
do
ApplicationSetting
.
last
ApplicationSetting
.
last
.
tap
do
|
settings
|
# do not cache nils
raise
'missing settings'
unless
settings
end
end
rescue
# Fall back to an uncached value if there are any problems (e.g. redis down)
...
...
changelogs/unreleased/fix-application-setting-nil-cache.yml
0 → 100644
View file @
8783c134
---
title
:
Fix application setting to cache nil object
merge_request
:
author
:
type
:
fixed
spec/models/application_setting_spec.rb
View file @
8783c134
...
...
@@ -220,6 +220,21 @@ describe ApplicationSetting do
expect
(
described_class
.
current
).
to
eq
(
:last
)
end
end
context
'when an ApplicationSetting is not yet present'
do
it
'does not cache nil object'
do
# when missing settings a nil object is returned, but not cached
allow
(
described_class
).
to
receive
(
:last
).
and_return
(
nil
).
twice
expect
(
described_class
.
current
).
to
be_nil
# when the settings are set the method returns a valid object
allow
(
described_class
).
to
receive
(
:last
).
and_return
(
:last
)
expect
(
described_class
.
current
).
to
eq
(
:last
)
# subsequent calls get everything from cache
expect
(
described_class
.
current
).
to
eq
(
:last
)
end
end
end
context
'restrict creating duplicates'
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