Commit cced33db authored by James Edwards-Jones's avatar James Edwards-Jones

CSV export performance optimizations

Avoids creating unnecessary arrays in Issuable#labels_hash
Uses cached issues count in CSV export modal
parent 572a21ff
......@@ -25,7 +25,6 @@ class Projects::IssuesController < Projects::ApplicationController
def index
@collection_type = "Issue"
@issues = issues_collection
@issues_count = @issues.count
@issues = @issues.page(params[:page])
@issuable_meta_data = issuable_meta_data(@issues, @collection_type)
......
......@@ -134,10 +134,7 @@ module IssuablesHelper
state_title = titles[state] || state.to_s.humanize
count =
Rails.cache.fetch(issuables_state_counter_cache_key(issuable_type, state), expires_in: 2.minutes) do
issuables_count_for_state(issuable_type, state)
end
count = cached_issuables_count_for_state(issuable_type, state)
html = content_tag(:span, state_title)
html << " " << content_tag(:span, number_with_delimiter(count), class: 'badge')
......@@ -145,6 +142,12 @@ module IssuablesHelper
html.html_safe
end
def cached_issuables_count_for_state(issuable_type, state)
Rails.cache.fetch(issuables_state_counter_cache_key(issuable_type, state), expires_in: 2.minutes) do
issuables_count_for_state(issuable_type, state)
end
end
def cached_assigned_issuables_count(assignee, issuable_type, state)
cache_key = hexdigest(['assigned_issuables_count', assignee.id, issuable_type, state].join('-'))
Rails.cache.fetch(cache_key, expires_in: 2.minutes) do
......
......@@ -179,8 +179,9 @@ module Issuable
end
def labels_hash
eager_load(:labels).pluck(:id, 'labels.title').inject(Hash.new([])) do |memo, (issue_id, label)|
memo[issue_id] += [label]
eager_load(:labels).pluck(:id, 'labels.title').inject({}) do |memo, (issue_id, label)|
memo[issue_id] ||= []
memo[issue_id] << label
memo
end
end
......
......@@ -10,7 +10,7 @@
.modal-header
= icon('check', { class: 'export-checkmark' })
%strong
#{@issues_count} issues selected
#{cached_issuables_count_for_state(:issues, params['state'])} issues selected
.modal-body
%div
The CSV export will be created in the background. Once it is finished, it will be attached to an email sent to
......
......@@ -12,7 +12,7 @@ describe 'Issues csv', feature: true do
def request_csv(params = {})
visit namespace_project_issues_path(project.namespace, project, params)
click_on 'Download CSV'
click_on 'Export as CSV'
click_on 'Export issues'
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