diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-23 19:18:19 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-24 10:19:36 +0100 |
commit | 4d2e7894efa36cc1b5de9432e25fcf22b6cf1d59 (patch) | |
tree | f3fc688746a80361d5688e8bae6d385d22a1c88d | |
parent | 7100b76923fc88667b1bd22b34f0a43323fe84b0 (diff) | |
download | gitlab-ce-4d2e7894efa36cc1b5de9432e25fcf22b6cf1d59.tar.gz |
Make API::Helpers find a project with only one query
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | changelogs/unreleased/22373-reduce-queries-in-api-helpers-find_project.yml | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 7 |
2 files changed, 10 insertions, 1 deletions
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 |