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
Jérome Perrin
gitlab-ce
Commits
e292bf5b
Commit
e292bf5b
authored
Nov 30, 2017
by
Brett Walker
Committed by
Stan Hu
Nov 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow caching options to be specified for counting services
parent
bfac8b7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
app/services/base_count_service.rb
app/services/base_count_service.rb
+7
-1
spec/services/base_count_service_spec.rb
spec/services/base_count_service_spec.rb
+6
-0
No files found.
app/services/base_count_service.rb
View file @
e292bf5b
...
@@ -9,7 +9,7 @@ class BaseCountService
...
@@ -9,7 +9,7 @@ class BaseCountService
end
end
def
count
def
count
Rails
.
cache
.
fetch
(
cache_key
,
raw:
raw?
)
{
uncached_count
}.
to_i
Rails
.
cache
.
fetch
(
cache_key
,
cache_options
)
{
uncached_count
}.
to_i
end
end
def
refresh_cache
def
refresh_cache
...
@@ -31,4 +31,10 @@ class BaseCountService
...
@@ -31,4 +31,10 @@ class BaseCountService
def
cache_key
def
cache_key
raise
NotImplementedError
,
'cache_key must be implemented and return a String'
raise
NotImplementedError
,
'cache_key must be implemented and return a String'
end
end
# subclasses can override to add any specific options, such as
# super.merge({ expires_in: 5.minutes })
def
cache_options
{
raw:
raw?
}
end
end
end
spec/services/base_count_service_spec.rb
View file @
e292bf5b
...
@@ -77,4 +77,10 @@ describe BaseCountService, :use_clean_rails_memory_store_caching do
...
@@ -77,4 +77,10 @@ describe BaseCountService, :use_clean_rails_memory_store_caching do
expect
{
service
.
cache_key
}.
to
raise_error
(
NotImplementedError
)
expect
{
service
.
cache_key
}.
to
raise_error
(
NotImplementedError
)
end
end
end
end
describe
'#cache_options'
do
it
'returns the default in options'
do
expect
(
service
.
cache_options
).
to
eq
({
raw:
false
})
end
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