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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
3df677a9
Commit
3df677a9
authored
Nov 09, 2017
by
George Andrinopoulos
Committed by
Winnie Hellmann
Nov 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move update_project_counter_caches? out of issue and merge request
parent
57a27023
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
39 deletions
+14
-39
app/models/issue.rb
app/models/issue.rb
+0
-4
app/models/merge_request.rb
app/models/merge_request.rb
+0
-4
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+5
-1
app/services/issues/base_service.rb
app/services/issues/base_service.rb
+4
-0
changelogs/unreleased/39602-move-update-project-counter-caches-out-of-issues-merge-requests.yml
...e-project-counter-caches-out-of-issues-merge-requests.yml
+5
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+0
-18
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+0
-12
No files found.
app/models/issue.rb
View file @
3df677a9
...
@@ -262,10 +262,6 @@ class Issue < ActiveRecord::Base
...
@@ -262,10 +262,6 @@ class Issue < ActiveRecord::Base
true
true
end
end
def
update_project_counter_caches?
state_changed?
||
confidential_changed?
end
def
update_project_counter_caches
def
update_project_counter_caches
Projects
::
OpenIssuesCountService
.
new
(
project
).
refresh_cache
Projects
::
OpenIssuesCountService
.
new
(
project
).
refresh_cache
end
end
...
...
app/models/merge_request.rb
View file @
3df677a9
...
@@ -958,10 +958,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -958,10 +958,6 @@ class MergeRequest < ActiveRecord::Base
true
true
end
end
def
update_project_counter_caches?
state_changed?
end
def
update_project_counter_caches
def
update_project_counter_caches
Projects
::
OpenMergeRequestsCountService
.
new
(
target_project
).
refresh_cache
Projects
::
OpenMergeRequestsCountService
.
new
(
target_project
).
refresh_cache
end
end
...
...
app/services/issuable_base_service.rb
View file @
3df677a9
...
@@ -187,7 +187,7 @@ class IssuableBaseService < BaseService
...
@@ -187,7 +187,7 @@ class IssuableBaseService < BaseService
# We have to perform this check before saving the issuable as Rails resets
# We have to perform this check before saving the issuable as Rails resets
# the changed fields upon calling #save.
# the changed fields upon calling #save.
update_project_counters
=
issuable
.
project
&&
issuable
.
update_project_counter_caches?
update_project_counters
=
issuable
.
project
&&
update_project_counter_caches?
(
issuable
)
if
issuable
.
with_transaction_returning_status
{
issuable
.
save
}
if
issuable
.
with_transaction_returning_status
{
issuable
.
save
}
# We do not touch as it will affect a update on updated_at field
# We do not touch as it will affect a update on updated_at field
...
@@ -288,4 +288,8 @@ class IssuableBaseService < BaseService
...
@@ -288,4 +288,8 @@ class IssuableBaseService < BaseService
# override if needed
# override if needed
def
execute_hooks
(
issuable
,
action
=
'open'
,
params
=
{})
def
execute_hooks
(
issuable
,
action
=
'open'
,
params
=
{})
end
end
def
update_project_counter_caches?
(
issuable
)
issuable
.
state_changed?
end
end
end
app/services/issues/base_service.rb
View file @
3df677a9
...
@@ -45,5 +45,9 @@ module Issues
...
@@ -45,5 +45,9 @@ module Issues
params
.
delete
(
:assignee_ids
)
params
.
delete
(
:assignee_ids
)
end
end
end
end
def
update_project_counter_caches?
(
issue
)
super
||
issue
.
confidential_changed?
end
end
end
end
end
changelogs/unreleased/39602-move-update-project-counter-caches-out-of-issues-merge-requests.yml
0 → 100644
View file @
3df677a9
---
title
:
Move update_project_counter_caches? out of issue and merge request
merge_request
:
15300
author
:
George Andrinopoulos
type
:
other
spec/models/issue_spec.rb
View file @
3df677a9
...
@@ -765,22 +765,4 @@ describe Issue do
...
@@ -765,22 +765,4 @@ describe Issue do
expect
(
described_class
.
public_only
).
to
eq
([
public_issue
])
expect
(
described_class
.
public_only
).
to
eq
([
public_issue
])
end
end
end
end
describe
'#update_project_counter_caches?'
do
it
'returns true when the state changes'
do
subject
.
state
=
'closed'
expect
(
subject
.
update_project_counter_caches?
).
to
eq
(
true
)
end
it
'returns true when the confidential flag changes'
do
subject
.
confidential
=
true
expect
(
subject
.
update_project_counter_caches?
).
to
eq
(
true
)
end
it
'returns false when the state or confidential flag did not change'
do
expect
(
subject
.
update_project_counter_caches?
).
to
eq
(
false
)
end
end
end
end
spec/models/merge_request_spec.rb
View file @
3df677a9
...
@@ -1772,16 +1772,4 @@ describe MergeRequest do
...
@@ -1772,16 +1772,4 @@ describe MergeRequest do
.
to
change
{
project
.
open_merge_requests_count
}.
from
(
1
).
to
(
0
)
.
to
change
{
project
.
open_merge_requests_count
}.
from
(
1
).
to
(
0
)
end
end
end
end
describe
'#update_project_counter_caches?'
do
it
'returns true when the state changes'
do
subject
.
state
=
'closed'
expect
(
subject
.
update_project_counter_caches?
).
to
eq
(
true
)
end
it
'returns false when the state did not change'
do
expect
(
subject
.
update_project_counter_caches?
).
to
eq
(
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