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
4b17356d
Commit
4b17356d
authored
Jan 21, 2021
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply reviewer feedback
- Setup associations - Minor stylistics changes
parent
51097771
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
24 additions
and
8 deletions
+24
-8
app/graphql/resolvers/project_merge_requests_resolver.rb
app/graphql/resolvers/project_merge_requests_resolver.rb
+5
-4
app/models/merge_request/metrics.rb
app/models/merge_request/metrics.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-0
config/feature_flags/development/optimized_merge_request_count_with_merged_at_filter.yml
...t/optimized_merge_request_count_with_merged_at_filter.yml
+1
-1
spec/finders/merge_request/metrics_finder_spec.rb
spec/finders/merge_request/metrics_finder_spec.rb
+2
-2
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+2
-0
spec/models/merge_request/metrics_spec.rb
spec/models/merge_request/metrics_spec.rb
+11
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-0
No files found.
app/graphql/resolvers/project_merge_requests_resolver.rb
View file @
4b17356d
...
...
@@ -28,14 +28,15 @@ module Resolvers
argument_names
.
delete
(
:merged_before
)
argument_names
.
delete
(
:merged_after
)
# no extra filtering arguments are provided
return
unless
argument_names
.
empty?
return
unless
args
[
:merged_after
]
||
args
[
:merged_before
]
# Detecting a specific query pattern:
# mergeRequests(mergedAfter: "X", mergedBefore: "Y") {
# count
# }
lookahead
.
selects?
(
:count
)
&&
lookahead
.
selections
.
size
==
1
&&
# no other nodes are selected
(
args
[
:merged_after
]
||
args
[
:merged_before
])
&&
argument_names
.
empty?
# no extra filtering arguments are provided
lookahead
.
selects?
(
:count
)
&&
lookahead
.
selections
.
size
==
1
# no other nodes are selected
end
end
end
app/models/merge_request/metrics.rb
View file @
4b17356d
...
...
@@ -5,7 +5,7 @@ class MergeRequest::Metrics < ApplicationRecord
belongs_to
:pipeline
,
class_name:
'Ci::Pipeline'
,
foreign_key: :pipeline_id
belongs_to
:latest_closed_by
,
class_name:
'User'
belongs_to
:merged_by
,
class_name:
'User'
belongs_to
:target_project
,
class_name:
'Project'
belongs_to
:target_project
,
class_name:
'Project'
,
inverse_of: :merge_requests
before_save
:ensure_target_project_id
...
...
app/models/project.rb
View file @
4b17356d
...
...
@@ -218,6 +218,7 @@ class Project < ApplicationRecord
# Merge Requests for target project should be removed with it
has_many
:merge_requests
,
foreign_key:
'target_project_id'
,
inverse_of: :target_project
has_many
:merge_request_metrics
,
foreign_key:
'target_project'
,
class_name:
'MergeRequest::Metrics'
,
inverse_of: :target_project
has_many
:source_of_merge_requests
,
foreign_key:
'source_project_id'
,
class_name:
'MergeRequest'
has_many
:issues
has_many
:labels
,
class_name:
'ProjectLabel'
...
...
config/feature_flags/development/optimized_merge_request_count_with_merged_at_filter.yml
View file @
4b17356d
...
...
@@ -2,7 +2,7 @@
name
:
optimized_merge_request_count_with_merged_at_filter
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52113
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/299347
milestone
:
'
13.
8
'
milestone
:
'
13.
9
'
type
:
development
group
:
group::optimize
default_enabled
:
false
spec/finders/merge_request/metrics_finder_spec.rb
View file @
4b17356d
...
...
@@ -6,13 +6,13 @@ RSpec.describe MergeRequest::MetricsFinder do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:merge_request_not_merged
)
{
create
(
:merge_request
,
:unique_branches
,
source_project:
project
)
}
let_it_be
(
:merged_at
)
{
Time
.
new
(
2020
,
5
,
1
)
}
let_it_be
(
:merge_request_merged
)
do
create
(
:merge_request
,
:unique_branches
,
:merged
,
source_project:
project
).
tap
do
|
mr
|
mr
.
metrics
.
update!
(
merged_at:
Time
.
new
(
2020
,
5
,
1
)
)
mr
.
metrics
.
update!
(
merged_at:
merged_at
)
end
end
let
(
:merged_at
)
{
merge_request_merged
.
metrics
.
merged_at
}
let
(
:params
)
do
{
target_project:
project
,
...
...
spec/lib/gitlab/import_export/all_models.yml
View file @
4b17356d
...
...
@@ -561,6 +561,7 @@ project:
-
exported_protected_branches
-
incident_management_oncall_schedules
-
debian_distributions
-
merge_request_metrics
award_emoji
:
-
awardable
-
user
...
...
@@ -589,6 +590,7 @@ lfs_file_locks:
project_badges
:
-
project
metrics
:
-
target_project
-
merge_request
-
latest_closed_by
-
merged_by
...
...
spec/models/merge_request/metrics_spec.rb
View file @
4b17356d
...
...
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec
.
describe
MergeRequest
::
Metrics
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:merge_request
)
}
it
{
is_expected
.
to
belong_to
(
:target_project
)
}
it
{
is_expected
.
to
belong_to
(
:latest_closed_by
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
belong_to
(
:merged_by
).
class_name
(
'User'
)
}
end
...
...
@@ -36,5 +37,15 @@ RSpec.describe MergeRequest::Metrics do
is_expected
.
not_to
include
([
metrics_2
])
end
end
describe
'.by_target_project'
do
let
(
:target_project
)
{
metrics_1
.
target_project
}
subject
{
described_class
.
by_target_project
(
target_project
)
}
it
'finds metrics record with the associated target project'
do
is_expected
.
to
eq
([
metrics_1
])
end
end
end
end
spec/models/project_spec.rb
View file @
4b17356d
...
...
@@ -21,6 +21,7 @@ RSpec.describe Project, factory_default: :keep do
it
{
is_expected
.
to
have_many
(
:services
)
}
it
{
is_expected
.
to
have_many
(
:events
)
}
it
{
is_expected
.
to
have_many
(
:merge_requests
)
}
it
{
is_expected
.
to
have_many
(
:merge_request_metrics
)
}
it
{
is_expected
.
to
have_many
(
:issues
)
}
it
{
is_expected
.
to
have_many
(
:milestones
)
}
it
{
is_expected
.
to
have_many
(
:iterations
)
}
...
...
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