diff --git a/changelogs/unreleased/22373-reduce-queries-in-api-helpers-find_project.yml b/changelogs/unreleased/22373-reduce-queries-in-api-helpers-find_project.yml new file mode 100644 index 0000000000000000000000000000000000000000..7f1d40e7c21f32e61454ae4049ee4686baddd30b --- /dev/null +++ b/changelogs/unreleased/22373-reduce-queries-in-api-helpers-find_project.yml @@ -0,0 +1,4 @@ +--- +title: 'Make API::Helpers find a project with only one query' +merge_request: 7714 +author: diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 2c593dbb4ea217e038c18683bbb3025ae2472c8f..60067758e955ebd46df56b358fc8a72d9f6049cf 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -76,7 +76,12 @@ module API end def find_project(id) - project = Project.find_with_namespace(id) || Project.find_by(id: id) + project = + if id =~ /^\d+$/ + Project.find_by(id: id) + else + Project.find_with_namespace(id) + end if can?(current_user, :read_project, project) project