Patch #24587

Improve custom fields list performance

Added by Thomas Löber 4 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Performance
Target version:3.4.0

Description

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

custom_fields_projects_count.diff Magnifier (1.65 KB) Thomas Löber, 2016-12-12 13:56

Associated revisions

Revision 16069
Added by Jean-Philippe Lang 4 months ago

Improve custom fields list performance (#24587).

Patch by Thomas Löber.

Revision 16070
Added by Jean-Philippe Lang 4 months ago

Make it work for 0 projects (#24587).

History

#1 Updated by Pavel Rosický 4 months ago

what about a counter cache? custom_field.projects_count?

#2 Updated by Jean-Philippe Lang 4 months ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.4.0

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.

Also available in: Atom PDF