Commit 3752f266 authored by charlieablett's avatar charlieablett

Use children rather than child_ids

- Direct children
parent 9cd77158
......@@ -138,11 +138,5 @@ module Types
resolve: -> (epic, args, ctx) do
Gitlab::Graphql::Aggregations::Epics::LazyEpicAggregate.new(ctx, epic.id, WEIGHT_SUM)
end
field :health_status,
::Types::HealthStatusEnum,
null: true,
description: 'Current health status',
feature_flag: :save_issuable_health_status
end
end
......@@ -14,7 +14,7 @@ module Gitlab
:direct_count_totals, :direct_weight_sum_totals, # only counts/weights of direct issues and child epic counts
:count_aggregate, :weight_sum_aggregate
attr_accessor :child_ids, :calculated_count_totals, :calculated_weight_sum_totals
attr_accessor :children, :calculated_count_totals, :calculated_weight_sum_totals
def initialize(epic_id, flat_info_list)
# epic aggregate records from the DB loader look like the following:
......@@ -23,7 +23,7 @@ module Gitlab
# so in order to get a sum of the entire tree, we have to add that up recursively
@epic_id = epic_id
@epic_info_flat_list = flat_info_list
@child_ids = []
@children = []
@direct_count_totals = []
@direct_weight_sum_totals = []
......@@ -43,7 +43,7 @@ module Gitlab
end
end
def assemble_epic_totals(children)
def assemble_epic_totals
[OPENED_EPIC_STATE, CLOSED_EPIC_STATE].each do |epic_state|
create_sum_if_needed(COUNT, epic_state, EPIC_TYPE, children.select { |node| node.epic_state_id == epic_state }.count)
end
......@@ -91,9 +91,7 @@ module Gitlab
return calculated_totals(facet) if calculated_totals(facet)
sum_total = []
child_ids.each do |child_id|
child = tree[child_id]
# get the child's totals, add to your own
children.each do |child|
child_sums = child.calculate_recursive_sums(facet, tree)
sum_total.concat(child_sums)
end
......@@ -101,6 +99,19 @@ module Gitlab
set_calculated_total(facet, sum_total)
end
def inspect
{
epic_id: @epic_id,
parent_id: @parent_id,
direct_count_totals: direct_count_totals,
direct_weight_sum_totals: direct_weight_sum_totals,
children: children,
object_id: object_id
}.to_json
end
alias_method :to_s, :inspect
private
def sum_objects(facet, state, type)
......
......@@ -87,10 +87,14 @@ module Gitlab
def assemble_direct_child_totals
tree.each do |_, node|
node_children = tree.select { |_, child_node| node.epic_id == child_node.parent_id }
node.child_ids = node_children.keys
node.assemble_epic_totals(node_children.values)
parent = tree[node.parent_id]
next if parent.nil?
parent.children << node
end
tree.each do |_, node|
node.assemble_epic_totals
node.assemble_issue_totals
end
end
......
......@@ -11,7 +11,7 @@ describe GitlabSchema.types['Epic'] do
closed_at created_at updated_at children has_children has_issues
web_path web_url relation_path reference issues user_permissions
notes discussions relative_position subscribed participants
descendant_counts descendant_weight_sum upvotes downvotes health_status
descendant_counts descendant_weight_sum upvotes downvotes
]
end
......
......@@ -110,11 +110,11 @@ describe Gitlab::Graphql::Aggregations::Epics::EpicNode do
let!(:child_epic_node) { described_class.new(child_epic_id, [{ parent_id: epic_id, epic_state_id: CLOSED_EPIC_STATE }]) }
before do
subject.child_ids << child_epic_id
subject.children << child_epic_node
end
it 'adds up the number of the child epics' do
subject.assemble_epic_totals([child_epic_node])
subject.assemble_epic_totals
expect(subject).to have_direct_total(EPIC_TYPE, COUNT_FACET, CLOSED_EPIC_STATE, 1)
end
......@@ -191,7 +191,7 @@ describe Gitlab::Graphql::Aggregations::Epics::EpicNode do
let(:immediate_weight_sum_totals) { [] }
before do
subject.child_ids << child_epic_id
subject.children << child_epic_node
allow(child_epic_node).to receive(:direct_totals).with(COUNT_FACET).and_return(child_count_totals)
allow(child_epic_node).to receive(:direct_totals).with(WEIGHT_SUM_FACET).and_return(child_weight_sum_totals)
end
......
......@@ -98,7 +98,7 @@ describe Gitlab::Graphql::Aggregations::Epics::LazyEpicAggregate do
tree = lazy_state[:tree]
expect(tree[child_epic_id].parent_id).to eq epic_id
expect(tree[epic_id].child_ids).to match_array([child_epic_id])
expect(tree[epic_id].children.map(&:epic_id)).to match_array([child_epic_id])
end
context 'for a parent-child relationship' do
......
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