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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
8835b788
Commit
8835b788
authored
Jun 01, 2016
by
Josh Frye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flush cache in callback. Add tests
parent
bfccea37
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+8
-0
app/models/user.rb
app/models/user.rb
+9
-4
spec/features/issues_spec.rb
spec/features/issues_spec.rb
+15
-0
No files found.
app/models/concerns/issuable.rb
View file @
8835b788
...
@@ -68,6 +68,14 @@ module Issuable
...
@@ -68,6 +68,14 @@ module Issuable
strip_attributes
:title
strip_attributes
:title
acts_as_paranoid
acts_as_paranoid
after_save
:update_assignee_cache_counts
,
if: :assignee_id_changed?
def
update_assignee_cache_counts
# make sure we flush the cache for both the old *and* new assignee
User
.
find
(
assignee_id_was
).
update_cache_counts
if
assignee_id_was
assignee
.
update_cache_counts
if
assignee_id
end
end
end
module
ClassMethods
module
ClassMethods
...
...
app/models/user.rb
View file @
8835b788
...
@@ -776,18 +776,23 @@ class User < ActiveRecord::Base
...
@@ -776,18 +776,23 @@ class User < ActiveRecord::Base
notification_settings
.
find_or_initialize_by
(
source:
source
)
notification_settings
.
find_or_initialize_by
(
source:
source
)
end
end
def
assigned_open_merge_request_count
def
assigned_open_merge_request_count
(
force:
false
)
Rails
.
cache
.
fetch
([
'users'
,
id
,
'assigned_open_merge_request_count'
],
expires_in:
60
)
do
Rails
.
cache
.
fetch
([
'users'
,
id
,
'assigned_open_merge_request_count'
],
force:
force
)
do
assigned_merge_requests
.
opened
.
count
assigned_merge_requests
.
opened
.
count
end
end
end
end
def
assigned_open_issues_count
def
assigned_open_issues_count
(
force:
false
)
Rails
.
cache
.
fetch
([
'users'
,
id
,
'assigned_open_issues_count'
],
expires_in:
60
)
do
Rails
.
cache
.
fetch
([
'users'
,
id
,
'assigned_open_issues_count'
],
force:
force
)
do
assigned_issues
.
opened
.
count
assigned_issues
.
opened
.
count
end
end
end
end
def
update_cache_counts
assigned_open_merge_request_count
(
force:
true
)
assigned_open_issues_count
(
force:
true
)
end
private
private
def
projects_union
def
projects_union
...
...
spec/features/issues_spec.rb
View file @
8835b788
...
@@ -62,6 +62,21 @@ describe 'Issues', feature: true do
...
@@ -62,6 +62,21 @@ describe 'Issues', feature: true do
expect
(
issue
.
reload
.
assignee
).
to
be_nil
expect
(
issue
.
reload
.
assignee
).
to
be_nil
end
end
it
'updates assigned cache count on change'
,
js:
true
do
visit
edit_namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
)
expect
(
page
).
to
have_content
"Assignee
#{
@user
.
name
}
"
expect
(
@user
.
assigned_open_issues_count
).
to
eq
@user
.
assigned_issues
.
opened
.
count
first
(
'#s2id_issue_assignee_id'
).
click
sleep
2
# wait for ajax stuff to complete
first
(
'.user-result'
).
click
click_button
'Save changes'
expect
(
@user
.
assigned_open_issues_count
).
to
eq
@user
.
assigned_issues
.
opened
.
count
end
end
end
describe
'due date'
,
js:
true
do
describe
'due date'
,
js:
true
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