プロジェクト

全般

プロフィール

Vote #78048

完了

Improve custom fields list performance

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Performance_53
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
53
version_id:
119
issue_org_id:
24587
author_id:
291
assigned_to_id:
1
comments:
2
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

The custom fields list displays the number of projects the issue custom field is used in by doing a database query for each custom field:

custom_field.projects.count

To improve the performance dramatically when there are really lots of issue custom fields the counts should be pre-loaded with a single database query:

@custom_fields_projects_count = IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count

In the view the counts can then be accessed by:

@custom_fields_projects_count[custom_field.id]

A patch file is attached.

Regards,
Thomas


journals

what about a counter cache? custom_field.projects_count?
--------------------------------------------------------------------------------
Patch committed with a slight change to handle the case where there are 0 projects that use the field.

> what about a counter cache? custom_field.projects_count?

Adding a cache counter for that seems a bit overkill to me.
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリPerformance_53 にセット
  • 対象バージョン3.4.0_119 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0