summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-09-11 23:16:40 -0700
committerStan Hu <stanhu@gmail.com>2019-09-11 23:24:14 -0700
commitc13c7e6709bf4748bbe411e9fd35a2436dcde421 (patch)
treee470b84c29c2c7999041042c137d15887bda5994
parent80e9f7f3463cc67c6eb1dd22fb9e2dc88ebed3f1 (diff)
downloadgitlab-ce-c13c7e6709bf4748bbe411e9fd35a2436dcde421.tar.gz
Fix member expiration not always workingsh-add-index-members-expires
The Sidekiq job `RemoveExpiredMembersWorker` was failing to run in production because it was hitting statement timeouts because it was scanning all rows in order. On staging, where it used to scan 4 million rows, adding an index brought this down to only a few hundred rows. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/67286
-rw-r--r--changelogs/unreleased/sh-add-index-members-expires.yml5
-rw-r--r--db/migrate/20190912061145_add_index_to_members_on_expires_at.rb17
-rw-r--r--db/schema.rb3
3 files changed, 24 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-add-index-members-expires.yml b/changelogs/unreleased/sh-add-index-members-expires.yml
new file mode 100644
index 00000000000..9b18dfa2420
--- /dev/null
+++ b/changelogs/unreleased/sh-add-index-members-expires.yml
@@ -0,0 +1,5 @@
+---
+title: Fix member expiration not always working
+merge_request: 32951
+author:
+type: performance
diff --git a/db/migrate/20190912061145_add_index_to_members_on_expires_at.rb b/db/migrate/20190912061145_add_index_to_members_on_expires_at.rb
new file mode 100644
index 00000000000..e961977747b
--- /dev/null
+++ b/db/migrate/20190912061145_add_index_to_members_on_expires_at.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class AddIndexToMembersOnExpiresAt < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :members, :expires_at
+ end
+
+ def down
+ remove_concurrent_index :members, :expires_at
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3906976d296..39faf1e651e 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_10_000130) do
+ActiveRecord::Schema.define(version: 2019_09_12_061145) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -1997,6 +1997,7 @@ ActiveRecord::Schema.define(version: 2019_09_10_000130) do
t.boolean "ldap", default: false, null: false
t.boolean "override", default: false, null: false
t.index ["access_level"], name: "index_members_on_access_level"
+ t.index ["expires_at"], name: "index_members_on_expires_at"
t.index ["invite_email"], name: "index_members_on_invite_email"
t.index ["invite_token"], name: "index_members_on_invite_token", unique: true
t.index ["requested_at"], name: "index_members_on_requested_at"