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
f0c0bdc0
Commit
f0c0bdc0
authored
May 12, 2017
by
Sean McGivern
Committed by
Timothy Andrew
May 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'update_assignee_cache_counts_refactoring' into 'master'
Rework update_assignee_cache_counts Closes #31873 See merge request !11270
parent
aa7f474c
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
68 additions
and
99 deletions
+68
-99
issue_assignee.rb
app/models/issue_assignee.rb
+0
-7
merge_request.rb
app/models/merge_request.rb
+0
-8
user.rb
app/models/user.rb
+5
-0
issuable_base_service.rb
app/services/issuable_base_service.rb
+6
-0
authorized_destroy_service.rb
app/services/members/authorized_destroy_service.rb
+2
-1
issuables_counter_spec.rb
spec/features/dashboard/issuables_counter_spec.rb
+3
-1
issue_spec.rb
spec/models/issue_spec.rb
+0
-40
merge_request_spec.rb
spec/models/merge_request_spec.rb
+0
-42
create_service_spec.rb
spec/services/issues/create_service_spec.rb
+16
-0
update_service_spec.rb
spec/services/issues/update_service_spec.rb
+7
-0
create_service_spec.rb
spec/services/merge_requests/create_service_spec.rb
+20
-0
update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+9
-0
No files found.
app/models/issue_assignee.rb
View file @
f0c0bdc0
...
...
@@ -3,11 +3,4 @@ class IssueAssignee < ActiveRecord::Base
belongs_to
:issue
belongs_to
:assignee
,
class_name:
"User"
,
foreign_key: :user_id
after_create
:update_assignee_cache_counts
after_destroy
:update_assignee_cache_counts
def
update_assignee_cache_counts
assignee
&
.
update_cache_counts
end
end
app/models/merge_request.rb
View file @
f0c0bdc0
...
...
@@ -123,7 +123,6 @@ class MergeRequest < ActiveRecord::Base
participant
:assignee
after_save
:keep_around_commit
after_save
:update_assignee_cache_counts
,
if: :assignee_id_changed?
def
self
.
reference_prefix
'!'
...
...
@@ -185,13 +184,6 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?
(
title
)
?
title
:
"WIP:
#{
title
}
"
end
def
update_assignee_cache_counts
# make sure we flush the cache for both the old *and* new assignees(if they exist)
previous_assignee
=
User
.
find_by_id
(
assignee_id_was
)
if
assignee_id_was
previous_assignee
&
.
update_cache_counts
assignee
&
.
update_cache_counts
end
# Returns a Hash of attributes to be used for Twitter card metadata
def
card_attributes
{
...
...
app/models/user.rb
View file @
f0c0bdc0
...
...
@@ -919,6 +919,11 @@ class User < ActiveRecord::Base
assigned_open_issues_count
(
force:
true
)
end
def
invalidate_cache_counts
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_merge_requests_count'
])
Rails
.
cache
.
delete
([
'users'
,
id
,
'assigned_open_issues_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 @
f0c0bdc0
...
...
@@ -178,6 +178,7 @@ class IssuableBaseService < BaseService
after_create
(
issuable
)
issuable
.
create_cross_references!
(
current_user
)
execute_hooks
(
issuable
)
issuable
.
assignees
.
each
(
&
:invalidate_cache_counts
)
end
issuable
...
...
@@ -234,6 +235,11 @@ class IssuableBaseService < BaseService
old_assignees:
old_assignees
)
if
old_assignees
!=
issuable
.
assignees
assignees
=
old_assignees
+
issuable
.
assignees
.
to_a
assignees
.
compact
.
each
(
&
:invalidate_cache_counts
)
end
after_update
(
issuable
)
issuable
.
create_new_cross_references!
(
current_user
)
execute_hooks
(
issuable
,
'update'
)
...
...
app/services/members/authorized_destroy_service.rb
View file @
f0c0bdc0
...
...
@@ -52,8 +52,9 @@ module Members
delete_all
project
.
merge_requests
.
opened
.
assigned_to
(
member
.
user
).
update_all
(
assignee_id:
nil
)
member
.
user
.
update_cache_counts
end
member
.
user
.
invalidate_cache_counts
end
end
end
spec/features/dashboard/issuables_counter_spec.rb
View file @
f0c0bdc0
...
...
@@ -19,7 +19,7 @@ describe 'Navigation bar counter', feature: true, caching: true do
issue
.
assignees
=
[]
user
.
up
date_cache_counts
user
.
invali
date_cache_counts
Timecop
.
travel
(
3
.
minutes
.
from_now
)
do
visit
issues_path
...
...
@@ -35,6 +35,8 @@ describe 'Navigation bar counter', feature: true, caching: true do
merge_request
.
update
(
assignee:
nil
)
user
.
invalidate_cache_counts
Timecop
.
travel
(
3
.
minutes
.
from_now
)
do
visit
merge_requests_path
...
...
spec/models/issue_spec.rb
View file @
f0c0bdc0
...
...
@@ -38,46 +38,6 @@ describe Issue, models: true do
end
end
describe
"before_save"
do
describe
"#update_cache_counts when an issue is reassigned"
do
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:assignee
)
{
create
(
:user
)
}
context
"when previous assignee exists"
do
before
do
issue
.
project
.
team
<<
[
assignee
,
:developer
]
issue
.
assignees
<<
assignee
end
it
"updates cache counts for new assignee"
do
user
=
create
(
:user
)
expect
(
user
).
to
receive
(
:update_cache_counts
)
issue
.
assignees
<<
user
end
it
"updates cache counts for previous assignee"
do
issue
.
assignees
.
first
expect_any_instance_of
(
User
).
to
receive
(
:update_cache_counts
)
issue
.
assignees
.
destroy_all
end
end
context
"when previous assignee does not exist"
do
it
"updates cache count for the new assignee"
do
issue
.
assignees
=
[]
expect_any_instance_of
(
User
).
to
receive
(
:update_cache_counts
)
issue
.
assignees
<<
assignee
end
end
end
end
describe
'#card_attributes'
do
it
'includes the author name'
do
allow
(
subject
).
to
receive
(
:author
).
and_return
(
double
(
name:
'Robert'
))
...
...
spec/models/merge_request_spec.rb
View file @
f0c0bdc0
...
...
@@ -87,48 +87,6 @@ describe MergeRequest, models: true do
end
end
describe
"before_save"
do
describe
"#update_cache_counts when a merge request is reassigned"
do
let
(
:project
)
{
create
:project
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:assignee
)
{
create
:user
}
context
"when previous assignee exists"
do
before
do
project
.
team
<<
[
assignee
,
:developer
]
merge_request
.
update
(
assignee:
assignee
)
end
it
"updates cache counts for new assignee"
do
user
=
create
(
:user
)
expect
(
user
).
to
receive
(
:update_cache_counts
)
merge_request
.
update
(
assignee:
user
)
end
it
"updates cache counts for previous assignee"
do
old_assignee
=
merge_request
.
assignee
allow
(
User
).
to
receive
(
:find_by_id
).
with
(
old_assignee
.
id
).
and_return
(
old_assignee
)
expect
(
old_assignee
).
to
receive
(
:update_cache_counts
)
merge_request
.
update
(
assignee:
nil
)
end
end
context
"when previous assignee does not exist"
do
it
"updates cache count for the new assignee"
do
merge_request
.
update
(
assignee:
nil
)
expect_any_instance_of
(
User
).
to
receive
(
:update_cache_counts
)
merge_request
.
update
(
assignee:
assignee
)
end
end
end
end
describe
'#card_attributes'
do
it
'includes the author name'
do
allow
(
subject
).
to
receive
(
:author
).
and_return
(
double
(
name:
'Robert'
))
...
...
spec/services/issues/create_service_spec.rb
View file @
f0c0bdc0
...
...
@@ -118,6 +118,22 @@ describe Issues::CreateService, services: true do
end
end
context
'when assignee is set'
do
let
(
:opts
)
do
{
title:
'Title'
,
description:
'Description'
,
assignees:
[
assignee
]
}
end
it
'invalidates open issues counter for assignees when issue is assigned'
do
project
.
team
<<
[
assignee
,
:master
]
described_class
.
new
(
project
,
user
,
opts
).
execute
expect
(
assignee
.
assigned_open_issues_count
).
to
eq
1
end
end
it
'executes issue hooks when issue is not confidential'
do
opts
=
{
title:
'Title'
,
description:
'Description'
,
confidential:
false
}
...
...
spec/services/issues/update_service_spec.rb
View file @
f0c0bdc0
...
...
@@ -59,6 +59,13 @@ describe Issues::UpdateService, services: true do
expect
(
issue
.
due_date
).
to
eq
Date
.
tomorrow
end
it
'updates open issue counter for assignees when issue is reassigned'
do
update_issue
(
assignee_ids:
[
user2
.
id
])
expect
(
user3
.
assigned_open_issues_count
).
to
eq
0
expect
(
user2
.
assigned_open_issues_count
).
to
eq
1
end
it
'sorts issues as specified by parameters'
do
issue1
=
create
(
:issue
,
project:
project
,
assignees:
[
user3
])
issue2
=
create
(
:issue
,
project:
project
,
assignees:
[
user3
])
...
...
spec/services/merge_requests/create_service_spec.rb
View file @
f0c0bdc0
...
...
@@ -144,6 +144,26 @@ describe MergeRequests::CreateService, services: true do
expect
(
merge_request
.
assignee
).
to
eq
(
assignee
)
end
context
'when assignee is set'
do
let
(
:opts
)
do
{
title:
'Title'
,
description:
'Description'
,
assignee_id:
assignee
.
id
,
source_branch:
'feature'
,
target_branch:
'master'
}
end
it
'invalidates open merge request counter for assignees when merge request is assigned'
do
project
.
team
<<
[
assignee
,
:master
]
described_class
.
new
(
project
,
user
,
opts
).
execute
expect
(
assignee
.
assigned_open_merge_requests_count
).
to
eq
1
end
end
context
"when issuable feature is private"
do
before
do
project
.
project_feature
.
update
(
issues_access_level:
ProjectFeature
::
PRIVATE
,
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
f0c0bdc0
...
...
@@ -297,6 +297,15 @@ describe MergeRequests::UpdateService, services: true do
end
end
context
'when the assignee changes'
do
it
'updates open merge request counter for assignees when merge request is reassigned'
do
update_merge_request
(
assignee_id:
user2
.
id
)
expect
(
user3
.
assigned_open_merge_requests_count
).
to
eq
0
expect
(
user2
.
assigned_open_merge_requests_count
).
to
eq
1
end
end
context
'when the target branch change'
do
before
do
update_merge_request
({
target_branch:
'target'
})
...
...
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