Patch #26714

Updated by Toshi MARUYAMA about 1 year ago

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

<pre><code class="sql">

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 )
</code></pre>


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

<pre><code class="ruby">

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
</code></pre>

As shown in diff.rb

Back