Commit ea372fa8 authored by Stan Hu's avatar Stan Hu

Fix N+1 SQL regression in exporting issues to CSV

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50449 refactored
`ExportCsvService` to support both issues and requirements. However, it
introduced an N+1 SQL query when loading labels of the list of issues
that significantly slowed down exporting of many issues.

We bring back the memoization for labels inside the
`Issues::ExportCsvService` to avoid this.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/321622
parent 91550884
......@@ -5,6 +5,12 @@ module Issues
include Gitlab::Routing.url_helpers
include GitlabRoutingHelper
def initialize(issuables_relation, project)
super
@labels = @issuables.labels_hash
end
def email(user)
Notify.issues_csv_email(user, project, csv_data, csv_builder.status).deliver_now
end
......@@ -41,7 +47,7 @@ module Issues
end
def issue_labels(issue)
issuables.labels_hash[issue.id].sort.join(',').presence
@labels[issue.id].sort.join(',').presence
end
# rubocop: disable CodeReuse/ActiveRecord
......
---
title: Fix N+1 SQL regression in exporting issues to CSV
merge_request: 54287
author:
type: performance
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