Optimize API /groups/:id/projects by preloading assocations

Stan Hu requested to merge sh-optimize-groups-api into master

There are a number of N+1 queries:

SELECT COUNT(*) FROM "projects" INNER JOIN "forked_project_links" ON "projects"."id" = "forked_project_links"."forked_to_project_id" WHERE "forked_project_links"."forked_from_project_id" = $1 AND ("projects"."pending_delete" != $2)
SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
SELECT COUNT(*) FROM "issues" WHERE "issues"."deleted_at" IS NULL AND "issues"."project_id" = $1 AND ("issues"."state" IN ('opened')) AND "issues"."confidential" = $2

See http://profiler.gitlap.com/20171119/6caac0fe-04a6-4b91-9d75-0c887489f426.txt.gz for a sample dump.

Closes #40308 (closed)

Edited by Francisco Javier López (ex-Gitlab)

Merge request reports