Commit 4189f977 authored by Jan Provaznik's avatar Jan Provaznik

Minor fixes and cleanups

* Moved query to epic model
* method renaming
parent 9304505c
......@@ -191,6 +191,14 @@ module EE
)
end
def related_issues(ids:, preload: nil)
::Issue.select('issues.*, epic_issues.id as epic_issue_id, epic_issues.relative_position, epic_issues.epic_id as epic_id')
.joins(:epic_issue)
.preload(preload)
.where("epic_issues.epic_id": ids)
.order('epic_issues.relative_position, epic_issues.id')
end
private
def start_date_milestone_query
......@@ -330,12 +338,8 @@ module EE
end
def issues_readable_by(current_user, preload: nil)
related_issues = ::Issue.select('issues.*, epic_issues.id as epic_issue_id, epic_issues.relative_position')
.joins(:epic_issue)
.preload(preload)
.where("epic_issues.epic_id = #{id}")
.order('epic_issues.relative_position, epic_issues.id')
related_issues = self.class.related_issues(ids: id, preload: preload)
Ability.issues_readable_by_user(related_issues, current_user)
end
......
......@@ -9,17 +9,14 @@ module Gitlab
@user = user
end
# rubocop: disable CodeReuse/ActiveRecord
def find
BatchLoader::GraphQL.for(@model_id).batch(default_value: nil) do |ids, loader|
results = ::Issue.select('issues.*, epic_issues.epic_id as epic_id')
.joins(:epic_issue)
.where("epic_issues.epic_id": ids)
issues = ::Epic.related_issues(ids: ids, preload: { project: :namespace })
results.each do |record|
loader.call(record.epic_id) do |memo|
memo ||= Gitlab::Graphql::Authorize::AuthorizeArray.new(filter_authorized)
memo << record
issues.each do |issue|
loader.call(issue.epic_id) do |memo|
memo ||= Gitlab::Graphql::FilterableArray.new(filter_authorized)
memo << issue
end
end
end
......@@ -30,7 +27,6 @@ module Gitlab
Ability.issues_readable_by_user(issues, @user)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -9,8 +9,8 @@ module Gitlab
Gitlab::Graphql::Connections::KeysetConnection
)
GraphQL::Relay::BaseConnection.register_connection_implementation(
Gitlab::Graphql::Authorize::AuthorizeArray,
Gitlab::Graphql::Connections::AuthorizeArrayConnection
Gitlab::Graphql::FilterableArray,
Gitlab::Graphql::Connections::FilterableArrayConnection
)
end
end
......
......@@ -3,12 +3,11 @@
module Gitlab
module Graphql
module Connections
class AuthorizeArrayConnection < GraphQL::Relay::ArrayConnection
class FilterableArrayConnection < GraphQL::Relay::ArrayConnection
def paged_nodes
@authorized_nodes ||= begin
callback = nodes.callback
nodes = super
callback.call(nodes)
callback = nodes.filter_callback
callback.call(super)
end
end
end
......
......@@ -2,13 +2,11 @@
module Gitlab
module Graphql
module Authorize
class AuthorizeArray < Array
attr_reader :callback
class FilterableArray < Array
attr_reader :filter_callback
def initialize(callback)
@callback = callback
end
def initialize(filter_callback)
@filter_callback = filter_callback
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment