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
a4b0876b
Commit
a4b0876b
authored
May 16, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add attribute check in cached getter
parent
42ab6f85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
app/models/concerns/redis_cacheable.rb
app/models/concerns/redis_cacheable.rb
+2
-0
spec/models/concerns/redis_cacheable_spec.rb
spec/models/concerns/redis_cacheable_spec.rb
+4
-0
No files found.
app/models/concerns/redis_cacheable.rb
View file @
a4b0876b
...
...
@@ -8,6 +8,8 @@ module RedisCacheable
def
cached_attr_reader
(
*
attributes
)
attributes
.
each
do
|
attribute
|
define_method
(
attribute
)
do
raise
ArgumentError
,
"Not a database attribute"
unless
self
.
has_attribute?
(
attribute
)
cached_attribute
(
attribute
)
||
read_attribute
(
attribute
)
end
end
...
...
spec/models/concerns/redis_cacheable_spec.rb
View file @
a4b0876b
...
...
@@ -10,6 +10,10 @@ describe RedisCacheable do
def
cast_value_from_cache
(
attribute
,
cached_value
)
cached_value
end
def
has_attribute?
(
attribute
)
attributes
.
has_key?
(
attribute
)
end
end
end
...
...
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