Project

General

Profile

Actions

Patch #26714

closed

pluck instead of map in issue_query

Added by jwjw yy over 7 years ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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


Files

diff.rb.diff (1.8 KB) diff.rb.diff Toshi MARUYAMA, 2017-08-17 09:06
issue_query.diff (1.67 KB) issue_query.diff jwjw yy, 2017-08-17 23:21
issue_query.v3.diff (1.75 KB) issue_query.v3.diff Toshi MARUYAMA, 2017-08-18 05:53
Actions #1

Updated by Toshi MARUYAMA over 7 years ago

Actions #2

Updated by Toshi MARUYAMA over 7 years ago

  • File deleted (diff.rb)
Actions #3

Updated by Toshi MARUYAMA over 7 years ago

  • Description updated (diff)
Actions #4

Updated by Toshi MARUYAMA over 7 years ago

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

Updated by Toshi MARUYAMA over 7 years 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.

Actions #6

Updated by jwjw yy over 7 years ago

done

Actions #7

Updated by Toshi MARUYAMA over 7 years ago

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

Actions #8

Updated by jwjw yy over 7 years ago

  • Status changed from New to Resolved
Actions #9

Updated by Toshi MARUYAMA over 7 years ago

  • Status changed from Resolved to New
Actions #10

Updated by jwjw yy over 6 years ago

  • Status changed from New to Resolved

Removed advertisement -- Holger Just

Actions #11

Updated by Holger Just over 6 years ago

  • Status changed from Resolved to New
Actions #12

Updated by Jean-Philippe Lang over 5 years ago

  • Target version changed from 4.1.0 to 4.2.0

Need some work to avoid duplicate code with IssueQuery#versions.

Actions #13

Updated by Go MAEDA over 3 years ago

  • Target version changed from 4.2.0 to Candidate for next major release
Actions #14

Updated by Go MAEDA 10 months ago

  • Status changed from New to Closed
  • Target version deleted (Candidate for next major release)

The map was replaced with pluck in r21499.

Actions

Also available in: Atom PDF