Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-10-07 18:37:39 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2015-10-08 15:35:32 +0300
commit03417456f0b7db408bfefd28e5b9342889b7f711 (patch)
tree77da54c8c65a594672f0d5e3416caff05619a275 /db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb
parent1190d0ab3dc7a3025bf55b666f34d1a0b51a8d89 (diff)
Revamp finding projects by namespaces
By using a JOIN we can remove the need for using 2 separate queries to find a project by its namespace. Combined with an index (only needed for PostgreSQL) this reduces the query time from ~245 ms (~520 ms for the first call) down to roughly 10 ms (~15 ms for the first call).
Diffstat (limited to 'db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb')
-rw-r--r--db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb b/db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb
new file mode 100644
index 00000000000..7f6cd6d5a78
--- /dev/null
+++ b/db/migrate/20151007120511_namespaces_projects_path_lower_indexes.rb
@@ -0,0 +1,17 @@
+class NamespacesProjectsPathLowerIndexes < ActiveRecord::Migration
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab::Database.postgresql?
+
+ execute 'CREATE INDEX CONCURRENTLY index_on_namespaces_lower_path ON namespaces (LOWER(path));'
+ execute 'CREATE INDEX CONCURRENTLY index_on_projects_lower_path ON projects (LOWER(path));'
+ end
+
+ def down
+ return unless Gitlab::Database.postgresql?
+
+ remove_index :namespaces, name: :index_on_namespaces_lower_path
+ remove_index :projects, name: :index_on_projects_lower_path
+ end
+end