BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d0db4080
Commit
d0db4080
authored
May 17, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'counters_cache_invalidation' into 'master'
Invalidate cache for issue and MR counters separately See merge request !11394
parents
42814500
a6c0eb54
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
2 deletions
+49
-2
user.rb
app/models/user.rb
+9
-1
issuable_base_service.rb
app/services/issuable_base_service.rb
+8
-1
counters_cache_invalidation.yml
changelogs/unreleased/counters_cache_invalidation.yml
+4
-0
user_spec.rb
spec/models/user_spec.rb
+28
-0
No files found.
app/models/user.rb
View file @
d0db4080
...
@@ -930,10 +930,18 @@ class User < ActiveRecord::Base
...
@@ -930,10 +930,18 @@ class User < ActiveRecord::Base
end
end
def
invalidate_cache_counts
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'
])
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_issues_count'
])
end
end
def
invalidate_merge_request_cache_counts
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_merge_requests_count'
])
end
def
todos_done_count
(
force:
false
)
def
todos_done_count
(
force:
false
)
Rails
.
cache
.
fetch
([
'users'
,
id
,
'todos_done_count'
],
force:
force
)
do
Rails
.
cache
.
fetch
([
'users'
,
id
,
'todos_done_count'
],
force:
force
)
do
TodosFinder
.
new
(
self
,
state: :done
).
execute
.
count
TodosFinder
.
new
(
self
,
state: :done
).
execute
.
count
...
...
app/services/issuable_base_service.rb
View file @
d0db4080
...
@@ -179,6 +179,7 @@ class IssuableBaseService < BaseService
...
@@ -179,6 +179,7 @@ class IssuableBaseService < BaseService
issuable
.
create_cross_references!
(
current_user
)
issuable
.
create_cross_references!
(
current_user
)
execute_hooks
(
issuable
)
execute_hooks
(
issuable
)
issuable
.
assignees
.
each
(
&
:invalidate_cache_counts
)
issuable
.
assignees
.
each
(
&
:invalidate_cache_counts
)
invalidate_cache_counts
(
issuable
.
assignees
,
issuable
)
end
end
issuable
issuable
...
@@ -237,7 +238,7 @@ class IssuableBaseService < BaseService
...
@@ -237,7 +238,7 @@ class IssuableBaseService < BaseService
if
old_assignees
!=
issuable
.
assignees
if
old_assignees
!=
issuable
.
assignees
assignees
=
old_assignees
+
issuable
.
assignees
.
to_a
assignees
=
old_assignees
+
issuable
.
assignees
.
to_a
assignees
.
compact
.
each
(
&
:invalidate_cache_counts
)
invalidate_cache_counts
(
assignees
.
compact
,
issuable
)
end
end
after_update
(
issuable
)
after_update
(
issuable
)
...
@@ -330,4 +331,10 @@ class IssuableBaseService < BaseService
...
@@ -330,4 +331,10 @@ class IssuableBaseService < BaseService
create_labels_note
(
issuable
,
old_labels
)
if
issuable
.
labels
!=
old_labels
create_labels_note
(
issuable
,
old_labels
)
if
issuable
.
labels
!=
old_labels
end
end
def
invalidate_cache_counts
(
users
,
issuable
)
users
.
each
do
|
user
|
user
.
public_send
(
"invalidate_
#{
issuable
.
model_name
.
singular
}
_cache_counts"
)
end
end
end
end
changelogs/unreleased/counters_cache_invalidation.yml
0 → 100644
View file @
d0db4080
---
title
:
Invalidate cache for issue and MR counters more granularly
merge_request
:
author
:
spec/models/user_spec.rb
View file @
d0db4080
...
@@ -1777,4 +1777,32 @@ describe User, models: true do
...
@@ -1777,4 +1777,32 @@ describe User, models: true do
expect
(
user
.
preferred_language
).
to
eq
(
'en'
)
expect
(
user
.
preferred_language
).
to
eq
(
'en'
)
end
end
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
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