From 4d2e7894efa36cc1b5de9432e25fcf22b6cf1d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 23 Nov 2016 19:18:19 +0100 Subject: Make API::Helpers find a project with only one query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- .../22373-reduce-queries-in-api-helpers-find_project.yml | 4 ++++ lib/api/helpers.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/22373-reduce-queries-in-api-helpers-find_project.yml 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 00000000000..7f1d40e7c21 --- /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 2c593dbb4ea..60067758e95 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 -- cgit v1.2.1