Commit 42703a65 authored by Alper Akgun's avatar Alper Akgun

Optimizes the service desk issue counter queries

Removes distinct and adds an index for batch counting in usage data
parent ed7ae583
# frozen_string_literal: true
class AddIndexOnAuthorIdAndIdAndCreatedAtToIssues < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :issues, [:author_id, :id, :created_at]
end
def down
remove_concurrent_index :issues, [:author_id, :id, :created_at]
end
end
......@@ -2206,6 +2206,7 @@ ActiveRecord::Schema.define(version: 2020_03_06_170531) do
t.integer "duplicated_to_id"
t.integer "promoted_to_epic_id"
t.integer "health_status", limit: 2
t.index ["author_id", "id", "created_at"], name: "index_issues_on_author_id_and_id_and_created_at"
t.index ["author_id"], name: "index_issues_on_author_id"
t.index ["closed_by_id"], name: "index_issues_on_closed_by_id"
t.index ["confidential"], name: "index_issues_on_confidential"
......
---
title: Optimize service desk issue counters query performance in usage data
merge_request: 26445
author:
type: performance
......@@ -281,7 +281,7 @@ module EE
projects_jira_dvcs_cloud_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_cloud.where(time_period), :creator_id),
projects_jira_dvcs_server_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_server.where(time_period), :creator_id),
service_desk_enabled_projects: distinct_count(::Project.with_active_services.service_desk_enabled.where(time_period), :creator_id),
service_desk_issues: distinct_count(::Issue.service_desk.where(time_period)),
service_desk_issues: count(::Issue.service_desk.where(time_period)),
todos: distinct_count(::Todo.where(time_period), :author_id)
}
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