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
e072e9cc
Commit
e072e9cc
authored
May 11, 2021
by
Adam Cohen
Committed by
Kerri Miller
May 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary query from close_issue method [RUN ALL RSPEC] [RUN AS-IF-FOSS]
parent
10f7d325
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
7 deletions
+57
-7
app/models/issue.rb
app/models/issue.rb
+9
-1
app/services/issues/close_service.rb
app/services/issues/close_service.rb
+1
-2
changelogs/unreleased/4794-optimise-close-issue-method.yml
changelogs/unreleased/4794-optimise-close-issue-method.yml
+5
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+22
-2
spec/services/issues/close_service_spec.rb
spec/services/issues/close_service_spec.rb
+20
-2
No files found.
app/models/issue.rb
View file @
e072e9cc
...
@@ -176,8 +176,16 @@ class Issue < ApplicationRecord
...
@@ -176,8 +176,16 @@ class Issue < ApplicationRecord
state
:opened
,
value:
Issue
.
available_states
[
:opened
]
state
:opened
,
value:
Issue
.
available_states
[
:opened
]
state
:closed
,
value:
Issue
.
available_states
[
:closed
]
state
:closed
,
value:
Issue
.
available_states
[
:closed
]
before_transition
any
=>
:closed
do
|
issue
|
before_transition
any
=>
:closed
do
|
issue
,
transition
|
args
=
transition
.
args
issue
.
closed_at
=
issue
.
system_note_timestamp
issue
.
closed_at
=
issue
.
system_note_timestamp
next
if
args
.
empty?
next
unless
args
.
first
.
is_a?
(
User
)
issue
.
closed_by
=
args
.
first
end
end
before_transition
closed: :opened
do
|
issue
|
before_transition
closed: :opened
do
|
issue
|
...
...
app/services/issues/close_service.rb
View file @
e072e9cc
...
@@ -24,8 +24,7 @@ module Issues
...
@@ -24,8 +24,7 @@ module Issues
return
issue
return
issue
end
end
if
project
.
issues_enabled?
&&
issue
.
close
if
project
.
issues_enabled?
&&
issue
.
close
(
current_user
)
issue
.
update
(
closed_by:
current_user
)
event_service
.
close_issue
(
issue
,
current_user
)
event_service
.
close_issue
(
issue
,
current_user
)
create_note
(
issue
,
closed_via
)
if
system_note
create_note
(
issue
,
closed_via
)
if
system_note
...
...
changelogs/unreleased/4794-optimise-close-issue-method.yml
0 → 100644
View file @
e072e9cc
---
title
:
Remove unnecessary query from close_issue method
merge_request
:
61087
author
:
type
:
performance
spec/models/issue_spec.rb
View file @
e072e9cc
...
@@ -242,16 +242,36 @@ RSpec.describe Issue do
...
@@ -242,16 +242,36 @@ RSpec.describe Issue do
expect
{
issue
.
close
}.
to
change
{
issue
.
state_id
}.
from
(
open_state
).
to
(
closed_state
)
expect
{
issue
.
close
}.
to
change
{
issue
.
state_id
}.
from
(
open_state
).
to
(
closed_state
)
end
end
context
'when an argument is provided'
do
context
'and the argument is a User'
do
it
'changes closed_by to the given user'
do
expect
{
issue
.
close
(
user
)
}.
to
change
{
issue
.
closed_by
}.
from
(
nil
).
to
(
user
)
end
end
context
'and the argument is a not a User'
do
it
'does not change closed_by'
do
expect
{
issue
.
close
(
"test"
)
}.
not_to
change
{
issue
.
closed_by
}
end
end
end
context
'when an argument is not provided'
do
it
'does not change closed_by'
do
expect
{
issue
.
close
}.
not_to
change
{
issue
.
closed_by
}
end
end
end
end
describe
'#reopen'
do
describe
'#reopen'
do
let
(
:issue
)
{
create
(
:issue
,
project:
reusable_project
,
state:
'closed'
,
closed_at:
Time
.
current
,
closed_by:
user
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
reusable_project
,
state:
'closed'
,
closed_at:
Time
.
current
,
closed_by:
user
)
}
it
'sets closed_at to nil when an issue is reopend'
do
it
'sets closed_at to nil when an issue is reopen
e
d'
do
expect
{
issue
.
reopen
}.
to
change
{
issue
.
closed_at
}.
to
(
nil
)
expect
{
issue
.
reopen
}.
to
change
{
issue
.
closed_at
}.
to
(
nil
)
end
end
it
'sets closed_by to nil when an issue is reopend'
do
it
'sets closed_by to nil when an issue is reopen
e
d'
do
expect
{
issue
.
reopen
}.
to
change
{
issue
.
closed_by
}.
from
(
user
).
to
(
nil
)
expect
{
issue
.
reopen
}.
to
change
{
issue
.
closed_by
}.
from
(
user
).
to
(
nil
)
end
end
...
...
spec/services/issues/close_service_spec.rb
View file @
e072e9cc
...
@@ -91,7 +91,7 @@ RSpec.describe Issues::CloseService do
...
@@ -91,7 +91,7 @@ RSpec.describe Issues::CloseService do
end
end
end
end
context
'with in
n
active external issue tracker supporting close_issue'
do
context
'with inactive external issue tracker supporting close_issue'
do
let!
(
:external_issue_tracker
)
{
create
(
:jira_service
,
project:
project
,
active:
false
)
}
let!
(
:external_issue_tracker
)
{
create
(
:jira_service
,
project:
project
,
active:
false
)
}
it
'does not close the issue on the external issue tracker'
do
it
'does not close the issue on the external issue tracker'
do
...
@@ -220,6 +220,14 @@ RSpec.describe Issues::CloseService do
...
@@ -220,6 +220,14 @@ RSpec.describe Issues::CloseService do
end
end
end
end
it
'verifies the number of queries'
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
close_issue
}
expected_queries
=
23
expect
(
recorded
.
count
).
to
be
<=
expected_queries
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
end
it
'closes the issue'
do
it
'closes the issue'
do
close_issue
close_issue
...
@@ -230,7 +238,7 @@ RSpec.describe Issues::CloseService do
...
@@ -230,7 +238,7 @@ RSpec.describe Issues::CloseService do
it
'records closed user'
do
it
'records closed user'
do
close_issue
close_issue
expect
(
issue
.
closed_by_id
).
to
be
(
user
.
id
)
expect
(
issue
.
reload
.
closed_by_id
).
to
be
(
user
.
id
)
end
end
it
'sends email to user2 about assign of new issue'
,
:sidekiq_might_not_need_inline
do
it
'sends email to user2 about assign of new issue'
,
:sidekiq_might_not_need_inline
do
...
@@ -254,6 +262,16 @@ RSpec.describe Issues::CloseService do
...
@@ -254,6 +262,16 @@ RSpec.describe Issues::CloseService do
expect
(
todo
.
reload
).
to
be_done
expect
(
todo
.
reload
).
to
be_done
end
end
context
'when closing the issue fails'
do
it
'does not assign a closed_by value for the issue'
do
allow
(
issue
).
to
receive
(
:close
).
and_return
(
false
)
close_issue
expect
(
issue
.
closed_by_id
).
to
be_nil
end
end
context
'when there is an associated Alert Management Alert'
do
context
'when there is an associated Alert Management Alert'
do
context
'when alert can be resolved'
do
context
'when alert can be resolved'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
issue:
issue
,
project:
project
)
}
let!
(
:alert
)
{
create
(
:alert_management_alert
,
issue:
issue
,
project:
project
)
}
...
...
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