summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-08-07 17:21:45 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-08-07 17:23:05 +0200
commit3925bbdf4e6429e9909fbe3b02aebea5dd0ac868 (patch)
tree3c7af54ec1f79c67998f9828f88d48fa2264e098
parent81933cfdd3e23d24ae18c0d2f5452ecd9690ab63 (diff)
downloadgitlab-ce-project-url-constrainer-select.tar.gz
Don't SELECT * just to check if a project existsproject-url-constrainer-select
In ProjectUrlConstrainer we use Project.find_by_full_path to check if a project exists. This query however by default would perform a "SELECT *" when we only care about whether or not any rows would be returned. Since find_by_full_path does not return an ActiveRecord::Relation the easiest way to optimise this is to simply perform a "SELECT 1" instead.
-rw-r--r--changelogs/unreleased/project-url-constrainer-select.yml4
-rw-r--r--lib/constraints/project_url_constrainer.rb3
2 files changed, 6 insertions, 1 deletions
diff --git a/changelogs/unreleased/project-url-constrainer-select.yml b/changelogs/unreleased/project-url-constrainer-select.yml
new file mode 100644
index 00000000000..6d4fc98cac7
--- /dev/null
+++ b/changelogs/unreleased/project-url-constrainer-select.yml
@@ -0,0 +1,4 @@
+---
+title: Don't SELECT * just to check if a project exists
+merge_request:
+author:
diff --git a/lib/constraints/project_url_constrainer.rb b/lib/constraints/project_url_constrainer.rb
index 4c0aee6c48f..7b3cab11df1 100644
--- a/lib/constraints/project_url_constrainer.rb
+++ b/lib/constraints/project_url_constrainer.rb
@@ -6,6 +6,7 @@ class ProjectUrlConstrainer
return false unless DynamicPathValidator.valid_project_path?(full_path)
- Project.find_by_full_path(full_path, follow_redirects: request.get?).present?
+ Project.select(1)
+ .find_by_full_path(full_path, follow_redirects: request.get?).present?
end
end