diff options
author | Stan Hu <stanhu@gmail.com> | 2019-09-09 17:05:55 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-09-09 21:51:57 -0700 |
commit | 08c3e59aeed34ad71e74afb674ddda7327fdc3a7 (patch) | |
tree | 544d9fa244519ac8b18b29ff8abf47bfdd40b30a /db | |
parent | ffa5328c39f195d3253e586569fc2474d3aa6860 (diff) | |
download | gitlab-ce-08c3e59aeed34ad71e74afb674ddda7327fdc3a7.tar.gz |
Optimize /admin/applications so that it does not timeoutsh-fix-oauth-application-page
On our dev instance, /admin/applications as not loading because:
1. There was an unindexed query by `application_id`.
2. There was an expensive query that attempted to load 1 million
unique entries via ActiveRecord just to find the unique count.
We fix the first issue by adding an index for that column.
We fix the second issue with a simple SELECT COUNT(DISTINCT
resource_owner_id) SQL query.
In addition, we add pagination to avoid loading more than 20
applications at once.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/67228
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb | 17 | ||||
-rw-r--r-- | db/schema.rb | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb b/db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb new file mode 100644 index 00000000000..78f7c0ecf0f --- /dev/null +++ b/db/post_migrate/20190910000130_add_index_on_application_id_on_oauth_access_tokens.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexOnApplicationIdOnOauthAccessTokens < ActiveRecord::Migration[5.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :oauth_access_tokens, :application_id + end + + def down + remove_concurrent_index :oauth_access_tokens, :application_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ddfb8bcb39..342e3a8d623 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_09_05_223900) do +ActiveRecord::Schema.define(version: 2019_09_10_000130) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -2390,6 +2390,7 @@ ActiveRecord::Schema.define(version: 2019_09_05_223900) do t.datetime "revoked_at" t.datetime "created_at", null: false t.string "scopes" + t.index ["application_id"], name: "index_oauth_access_tokens_on_application_id" t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id" t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true |