Commit 0fc866aa authored by Alper Akgun's avatar Alper Akgun

Optimizes the notes counter query

Adds an index for batch counting in usage data
parent c943774f
---
title: Optimize notes counters in usage data
merge_request: 26871
author:
type: performance
# frozen_string_literal: true
class AddIndexOnAuthorIdAndIdAndCreatedAtToNotes < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :notes, [:author_id, :created_at]
remove_concurrent_index :notes, [:author_id]
end
def down
add_concurrent_index :notes, [:author_id]
remove_concurrent_index :notes, [:author_id, :created_at]
end
end
......@@ -2826,7 +2826,7 @@ ActiveRecord::Schema.define(version: 2020_03_11_165635) do
t.boolean "resolved_by_push"
t.bigint "review_id"
t.boolean "confidential"
t.index ["author_id"], name: "index_notes_on_author_id"
t.index ["author_id", "created_at"], name: "index_notes_on_author_id_and_created_at"
t.index ["commit_id"], name: "index_notes_on_commit_id"
t.index ["created_at"], name: "index_notes_on_created_at"
t.index ["discussion_id"], name: "index_notes_on_discussion_id"
......
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