Patch #26714

pluck instead of map in issue_query

Added by jwjw yy about 1 month ago. Updated about 1 month ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Code cleanup/refactoring
Target version:4.1.0

Description

The previous issue_query.rb, line 438 version_ids = versions(:conditions => [where]).map(&:id) will issue query as:

SELECT `versions`.`id` AS t0_r0, `versions`.`project_id` AS t0_r1, `versions`.`name` AS t0_r2, `versions`.`description` AS t0_r3, `versions`.`effective_date` AS t0_r4, `versions`.`created_on` AS t0_r5, `versions`.`updated_on` AS t0_r6, `versions`.`wiki_page_title` AS t0_r7, `versions`.`status` AS t0_r8, `versions`.`sharing` AS t0_r9, `projects`.`id` AS t1_r0, `projects`.`name` AS t1_r1, `projects`.`description` AS t1_r2, `projects`.`homepage` AS t1_r3, `projects`.`is_public` AS t1_r4, `projects`.`parent_id` AS t1_r5, `projects`.`created_on` AS t1_r6, `projects`.`updated_on` AS t1_r7, `projects`.`identifier` AS t1_r8, `projects`.`status` AS t1_r9, `projects`.`lft` AS t1_r10, `projects`.`rgt` AS t1_r11, `projects`.`inherit_members` AS t1_r12, `projects`.`default_version_id` AS t1_r13 FROM `versions` INNER JOIN `projects` ON `projects`.`id` = `versions`.`project_id` WHERE (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking')) AND ( 1 = 1 )

However, only id is needed, so , it's possible to change to

 version_ids = versions_for_id(:conditions => [where]).pluck(:id)
  def versions_for_id(options={})
    Version.visible.
      where(project_statement).
      where(options[:conditions]).
      includes(:project).
      references(:project)
  rescue ::ActiveRecord::StatementInvalid => e
    raise StatementInvalid.new(e.message)
  end    

As shown in diff.rb

diff.rb.diff Magnifier (1.8 KB) Toshi MARUYAMA, 2017-08-17 09:06

issue_query.diff Magnifier (1.67 KB) jwjw yy, 2017-08-17 23:21

issue_query.v3.diff Magnifier (1.75 KB) Toshi MARUYAMA, 2017-08-18 05:53

History

#1 Updated by Toshi MARUYAMA about 1 month ago

#2 Updated by Toshi MARUYAMA about 1 month ago

  • File deleted (diff.rb)

#3 Updated by Toshi MARUYAMA about 1 month ago

  • Description updated (diff)

#4 Updated by Toshi MARUYAMA about 1 month ago

  • Tracker changed from Defect to Patch
  • Category changed from Issues to Code cleanup/refactoring

#5 Updated by Toshi MARUYAMA about 1 month ago

  • Status changed from New to Needs feedback

I think your IssueQuery#versions_for_id is named IssueQuery#version_ids and pluck(:id) is in it for consistency.
source:tags/3.4.2/app/models/issue_query.rb#L310

Please add ".diff" in your patch file name and remove commented lines from your patch.

#6 Updated by jwjw yy about 1 month ago

done

#7 Updated by Toshi MARUYAMA about 1 month ago

  • File issue_query.v3.diffMagnifier added
  • Status changed from Needs feedback to New
  • Target version set to 4.1.0

pluck(:id) in IssueQuery#version_ids is missing.

#8 Updated by jwjw yy about 1 month ago

  • Status changed from New to Resolved

#9 Updated by Toshi MARUYAMA about 1 month ago

  • Status changed from Resolved to New

Also available in: Atom PDF