-
Yorick Peterse authored
When displaying a Group details page we check if epics are enabled for the group and all of its descendants. For this set we will eventually run at least one SQL query per Group to get the plans said Group has access to. In case of a hierarchy with 20 groups this means at least 20 SQL queries. In this commit we introduce Gitlab::GroupPlansPreloader. This is a custom class that takes an ActiveRecord::Relation of Group objects and efficiently preloads the plans for these groups. This class only needs three SQL queries to do its work: 1. A SQL query to get the groups and all of their ancestors. 2. A SQL query to get all the plans all of these groups have access to. 3. A SQL query to get the groups to assign the plans to, then return to the caller. Using this data the class can then determine which groups have access to what plans. Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/6206
348c89c4