Commit e37bd615 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Improve index for calendar query

Add action, target_type, and created_at to the index to improve query
for user's activities

Changelog: performance
parent c3f47d6d
# frozen_string_literal: true
class ImproveIndexOnEventsForCalendar < Gitlab::Database::Migration[1.0]
INDEX_NAME = 'index_events_author_id_project_id_action_target_type_created_at'
def up
prepare_async_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME
end
def down
unprepare_async_index :events, [:author_id, :project_id, :action, :target_type, :created_at], name: INDEX_NAME
end
end
e010b4c12ae8203d9ea8a4c2035be5e7165aba0030f4d5fd0b0f978f84748707
\ No newline at end of file
......@@ -29,13 +29,13 @@ module Gitlab
# project_features for the (currently) 3 different contribution types
date_from = @contributor_time_instance.now.years_ago(1)
repo_events = event_created_at(date_from, :repository)
.where(action: :pushed)
.where(action: :pushed, target_type: nil)
issue_events = event_created_at(date_from, :issues)
.where(action: [:created, :closed], target_type: "Issue")
mr_events = event_created_at(date_from, :merge_requests)
.where(action: [:merged, :created, :closed], target_type: "MergeRequest")
note_events = event_created_at(date_from, :merge_requests)
.where(action: :commented)
.where(action: :commented, target_type: "Note")
events = Event
.select("date(created_at + #{date_interval}) AS date", 'COUNT(*) AS num_events')
......
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