GraphQL: N+1 query issue when listing milestons
In app/graphql/types/milestone_type.rb
we use authorize :read_milestone
which checks read permission for each milestone being listed, but milestone's policy delegates permissions checking to it's parent:
class MilestonePolicy < BasePolicy
delegate { @subject.resource_parent }
end
Which leads to loading milestone's project/group for each milestone separately. We should preload milestone's resource parent when listing milestones.
The following discussion from !32496 (merged) should be addressed:
-
@jprovaznik started a discussion: (+3 comments) This could be simplified as:
def subgroup_milestone? group_milestone? && parent.subgroup? end
What exactly do we need subgroup_milestone for? A potential concern is that this introduces N+1 query issue (for each group milestone we have to query also it's group to check if it has parent_id set).
Also do we care here if the milestone is in ANY subgroup, or would we rather want to know whether the milestone is directly in the group for which we display the roadmap vs one of its subgroups?