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
a6c0eb54
Commit
a6c0eb54
authored
May 15, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invalidate cache for issue and MR counters more granularly
parent
e261b4b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
2 deletions
+49
-2
app/models/user.rb
app/models/user.rb
+9
-1
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+8
-1
changelogs/unreleased/counters_cache_invalidation.yml
changelogs/unreleased/counters_cache_invalidation.yml
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+28
-0
No files found.
app/models/user.rb
View file @
a6c0eb54
...
...
@@ -930,10 +930,18 @@ class User < ActiveRecord::Base
end
def
invalidate_cache_counts
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_merge_requests_count'
])
invalidate_issue_cache_counts
invalidate_merge_request_cache_counts
end
def
invalidate_issue_cache_counts
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_issues_count'
])
end
def
invalidate_merge_request_cache_counts
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_merge_requests_count'
])
end
def
todos_done_count
(
force:
false
)
Rails
.
cache
.
fetch
([
'users'
,
id
,
'todos_done_count'
],
force:
force
)
do
TodosFinder
.
new
(
self
,
state: :done
).
execute
.
count
...
...
app/services/issuable_base_service.rb
View file @
a6c0eb54
...
...
@@ -179,6 +179,7 @@ class IssuableBaseService < BaseService
issuable
.
create_cross_references!
(
current_user
)
execute_hooks
(
issuable
)
issuable
.
assignees
.
each
(
&
:invalidate_cache_counts
)
invalidate_cache_counts
(
issuable
.
assignees
,
issuable
)
end
issuable
...
...
@@ -237,7 +238,7 @@ class IssuableBaseService < BaseService
if
old_assignees
!=
issuable
.
assignees
assignees
=
old_assignees
+
issuable
.
assignees
.
to_a
assignees
.
compact
.
each
(
&
:invalidate_cache_counts
)
invalidate_cache_counts
(
assignees
.
compact
,
issuable
)
end
after_update
(
issuable
)
...
...
@@ -330,4 +331,10 @@ class IssuableBaseService < BaseService
create_labels_note
(
issuable
,
old_labels
)
if
issuable
.
labels
!=
old_labels
end
def
invalidate_cache_counts
(
users
,
issuable
)
users
.
each
do
|
user
|
user
.
public_send
(
"invalidate_
#{
issuable
.
model_name
.
singular
}
_cache_counts"
)
end
end
end
changelogs/unreleased/counters_cache_invalidation.yml
0 → 100644
View file @
a6c0eb54
---
title
:
Invalidate cache for issue and MR counters more granularly
merge_request
:
author
:
spec/models/user_spec.rb
View file @
a6c0eb54
...
...
@@ -1777,4 +1777,32 @@ describe User, models: true do
expect
(
user
.
preferred_language
).
to
eq
(
'en'
)
end
end
context
'#invalidate_issue_cache_counts'
do
let
(
:user
)
{
build_stubbed
(
:user
)
}
it
'invalidates cache for issue counter'
do
cache_mock
=
double
expect
(
cache_mock
).
to
receive
(
:delete
).
with
([
'users'
,
user
.
id
,
'assigned_open_issues_count'
])
allow
(
Rails
).
to
receive
(
:cache
).
and_return
(
cache_mock
)
user
.
invalidate_issue_cache_counts
end
end
context
'#invalidate_merge_request_cache_counts'
do
let
(
:user
)
{
build_stubbed
(
:user
)
}
it
'invalidates cache for Merge Request counter'
do
cache_mock
=
double
expect
(
cache_mock
).
to
receive
(
:delete
).
with
([
'users'
,
user
.
id
,
'assigned_open_merge_requests_count'
])
allow
(
Rails
).
to
receive
(
:cache
).
and_return
(
cache_mock
)
user
.
invalidate_merge_request_cache_counts
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