Skip to content

Add Project.where_paths_in

Yorick Peterse requested to merge finding-multiple-projects-by-paths into master

What does this MR do?

This MR adds the method Project.where_paths_in which can be used to find multiple projects by a list of full paths.

Are there points in the code the reviewer needs to double check?

No.

Why was this MR needed?

In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4410 I'm working on reducing the SQL queries needed to render Markdown. One reason for the large amount of queries is executing a large number of queries needed to find projects and related data. Basically Project.find_with_namespace is called in a loop and then any relations have to be retrieved separately.

By using Project.where_paths_in we can work around this by doing something like:

project_paths = [...] # populated by some method
projects = Project.where_paths_in(project_paths).includes(:namespace, ...)

What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/18042

Merge request reports