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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
e52b1df1
Commit
e52b1df1
authored
Apr 04, 2017
by
mhasbini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove useless queries with false conditions (e.g 1=0)
parent
9fc17f6f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
0 deletions
+64
-0
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+3
-0
app/workers/process_commit_worker.rb
app/workers/process_commit_worker.rb
+2
-0
changelogs/unreleased/29492-useless-queries.yml
changelogs/unreleased/29492-useless-queries.yml
+4
-0
spec/support/issuables_list_metadata_shared_examples.rb
spec/support/issuables_list_metadata_shared_examples.rb
+15
-0
spec/support/matchers/query_matcher.rb
spec/support/matchers/query_matcher.rb
+33
-0
spec/workers/process_commit_worker_spec.rb
spec/workers/process_commit_worker_spec.rb
+7
-0
No files found.
app/controllers/concerns/issuable_collections.rb
View file @
e52b1df1
...
@@ -15,6 +15,9 @@ module IssuableCollections
...
@@ -15,6 +15,9 @@ module IssuableCollections
# a new order into the collection.
# a new order into the collection.
# We cannot use reorder to not mess up the paginated collection.
# We cannot use reorder to not mess up the paginated collection.
issuable_ids
=
issuable_collection
.
map
(
&
:id
)
issuable_ids
=
issuable_collection
.
map
(
&
:id
)
return
{}
if
issuable_ids
.
empty?
issuable_note_count
=
Note
.
count_for_collection
(
issuable_ids
,
@collection_type
)
issuable_note_count
=
Note
.
count_for_collection
(
issuable_ids
,
@collection_type
)
issuable_votes_count
=
AwardEmoji
.
votes_for_collection
(
issuable_ids
,
@collection_type
)
issuable_votes_count
=
AwardEmoji
.
votes_for_collection
(
issuable_ids
,
@collection_type
)
issuable_merge_requests_count
=
issuable_merge_requests_count
=
...
...
app/workers/process_commit_worker.rb
View file @
e52b1df1
...
@@ -53,6 +53,8 @@ class ProcessCommitWorker
...
@@ -53,6 +53,8 @@ class ProcessCommitWorker
def
update_issue_metrics
(
commit
,
author
)
def
update_issue_metrics
(
commit
,
author
)
mentioned_issues
=
commit
.
all_references
(
author
).
issues
mentioned_issues
=
commit
.
all_references
(
author
).
issues
return
if
mentioned_issues
.
empty?
Issue
::
Metrics
.
where
(
issue_id:
mentioned_issues
.
map
(
&
:id
),
first_mentioned_in_commit_at:
nil
).
Issue
::
Metrics
.
where
(
issue_id:
mentioned_issues
.
map
(
&
:id
),
first_mentioned_in_commit_at:
nil
).
update_all
(
first_mentioned_in_commit_at:
commit
.
committed_date
)
update_all
(
first_mentioned_in_commit_at:
commit
.
committed_date
)
end
end
...
...
changelogs/unreleased/29492-useless-queries.yml
0 → 100644
View file @
e52b1df1
---
title
:
Remove useless queries with
false
conditions (e.g 1=0)
merge_request
:
10141
author
:
mhasbini
spec/support/issuables_list_metadata_shared_examples.rb
View file @
e52b1df1
...
@@ -33,4 +33,19 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
...
@@ -33,4 +33,19 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
expect
(
meta_data
[
id
].
upvotes
).
to
eq
(
id
+
2
)
expect
(
meta_data
[
id
].
upvotes
).
to
eq
(
id
+
2
)
end
end
end
end
describe
"when given empty collection"
do
let
(
:project2
)
{
create
(
:empty_project
,
:public
)
}
it
"doesn't execute any queries with false conditions"
do
get_action
=
if
action
proc
{
get
action
}
else
proc
{
get
:index
,
namespace_id:
project2
.
namespace
,
project_id:
project2
}
end
expect
(
&
get_action
).
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
end
end
end
end
spec/support/matchers/query_matcher.rb
0 → 100644
View file @
e52b1df1
RSpec
::
Matchers
.
define
:make_queries_matching
do
|
matcher
,
expected_count
=
nil
|
supports_block_expectations
match
do
|
block
|
@counter
=
query_count
(
matcher
,
&
block
)
if
expected_count
@counter
.
count
==
expected_count
else
@counter
.
count
>
0
end
end
failure_message_when_negated
do
|
_
|
if
expected_count
"expected
#{
matcher
}
not to match
#{
expected_count
}
queries, got
#{
@counter
.
count
}
matches:
\n\n
#{
@counter
.
inspect
}
"
else
"expected
#{
matcher
}
not to match any query, got
#{
@counter
.
count
}
matches:
\n\n
#{
@counter
.
inspect
}
"
end
end
failure_message
do
|
_
|
if
expected_count
"expected
#{
matcher
}
to match
#{
expected_count
}
queries, got
#{
@counter
.
count
}
matches:
\n\n
#{
@counter
.
inspect
}
"
else
"expected
#{
matcher
}
to match at least one query, got
#{
@counter
.
count
}
matches:
\n\n
#{
@counter
.
inspect
}
"
end
end
def
query_count
(
regex
,
&
block
)
@recorder
=
ActiveRecord
::
QueryRecorder
.
new
(
&
block
).
log
@recorder
.
select
{
|
q
|
q
.
match
(
regex
)
}
end
end
spec/workers/process_commit_worker_spec.rb
View file @
e52b1df1
...
@@ -99,6 +99,13 @@ describe ProcessCommitWorker do
...
@@ -99,6 +99,13 @@ describe ProcessCommitWorker do
expect
(
metric
.
first_mentioned_in_commit_at
).
to
eq
(
commit
.
committed_date
)
expect
(
metric
.
first_mentioned_in_commit_at
).
to
eq
(
commit
.
committed_date
)
end
end
it
"doesn't execute any queries with false conditions"
do
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Lorem Ipsum"
)
expect
{
worker
.
update_issue_metrics
(
commit
,
user
)
}.
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
end
end
end
describe
'#build_commit'
do
describe
'#build_commit'
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