Commit 3c98cabd authored by Toon Claes's avatar Toon Claes

Merge branch '210051-optimize-or-remove-ldap_users-counter' into 'master'

Optimize  or remove ldap_users counter

Closes #210051

See merge request gitlab-org/gitlab!27197
parents 813c6fee aa9e45fc
---
title: Optimize members counters query performance in usage data
merge_request: 27197
author:
type: performance
# frozen_string_literal: true
class AddIndexOnUserIdTypeSourceTypeLdapAndCreatedAtToMembers < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_members_on_user_id_created_at'
disable_ddl_transaction!
def up
add_concurrent_index :members, [:user_id, :created_at], where: "ldap = TRUE AND type = 'GroupMember' AND source_type = 'Namespace'", name: INDEX_NAME
end
def down
remove_concurrent_index :members, INDEX_NAME
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_03_12_163407) do ActiveRecord::Schema.define(version: 2020_03_13_123934) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm" enable_extension "pg_trgm"
...@@ -2442,6 +2442,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_163407) do ...@@ -2442,6 +2442,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_163407) do
t.index ["invite_token"], name: "index_members_on_invite_token", unique: true t.index ["invite_token"], name: "index_members_on_invite_token", unique: true
t.index ["requested_at"], name: "index_members_on_requested_at" t.index ["requested_at"], name: "index_members_on_requested_at"
t.index ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type" t.index ["source_id", "source_type"], name: "index_members_on_source_id_and_source_type"
t.index ["user_id", "created_at"], name: "index_members_on_user_id_created_at", where: "((ldap = true) AND ((type)::text = 'GroupMember'::text) AND ((source_type)::text = 'Namespace'::text))"
t.index ["user_id"], name: "index_members_on_user_id" t.index ["user_id"], name: "index_members_on_user_id"
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment