back out from r12715 to r12720: #connection replacing
These revisions have performance regression on Rails 3.2.16. git-svn-id: http://svn.redmine.org/redmine/trunk@12735 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
9e71d89cdb
commit
a711cbb44e
|
@ -1361,7 +1361,7 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
done = p.leaves.joins(:status).
|
done = p.leaves.joins(:status).
|
||||||
sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " +
|
sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " +
|
||||||
"* (CASE WHEN is_closed = #{ActiveRecord::Base.connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f
|
"* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f
|
||||||
progress = done / (average * leaves_count)
|
progress = done / (average * leaves_count)
|
||||||
p.done_ratio = progress.round
|
p.done_ratio = progress.round
|
||||||
p.done_ratio = 100 if p.done_ratio > 100
|
p.done_ratio = 100 if p.done_ratio > 100
|
||||||
|
|
|
@ -32,7 +32,7 @@ class IssueCustomField < CustomField
|
||||||
sql = super
|
sql = super
|
||||||
id_column ||= id
|
id_column ||= id
|
||||||
tracker_condition = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id_column})"
|
tracker_condition = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id_column})"
|
||||||
project_condition = "EXISTS (SELECT 1 FROM #{CustomField.table_name} ifa WHERE ifa.is_for_all = #{ActiveRecord::Base.connection.quoted_true} AND ifa.id = #{id_column})" +
|
project_condition = "EXISTS (SELECT 1 FROM #{CustomField.table_name} ifa WHERE ifa.is_for_all = #{connection.quoted_true} AND ifa.id = #{id_column})" +
|
||||||
" OR #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id_column})"
|
" OR #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id_column})"
|
||||||
|
|
||||||
"((#{sql}) AND (#{tracker_condition}) AND (#{project_condition}))"
|
"((#{sql}) AND (#{tracker_condition}) AND (#{project_condition}))"
|
||||||
|
|
|
@ -429,7 +429,7 @@ class IssueQuery < Query
|
||||||
" WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id))"
|
" WHERE #{Member.table_name}.project_id = #{Issue.table_name}.project_id))"
|
||||||
when "=", "!"
|
when "=", "!"
|
||||||
role_cond = value.any? ?
|
role_cond = value.any? ?
|
||||||
"#{MemberRole.table_name}.role_id IN (" + value.collect{|val| "'#{ActiveRecord::Base.connection.quote_string(val)}'"}.join(",") + ")" :
|
"#{MemberRole.table_name}.role_id IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" :
|
||||||
"1=0"
|
"1=0"
|
||||||
|
|
||||||
sw = operator == "!" ? 'NOT' : ''
|
sw = operator == "!" ? 'NOT' : ''
|
||||||
|
@ -441,7 +441,7 @@ class IssueQuery < Query
|
||||||
|
|
||||||
def sql_for_is_private_field(field, operator, value)
|
def sql_for_is_private_field(field, operator, value)
|
||||||
op = (operator == "=" ? 'IN' : 'NOT IN')
|
op = (operator == "=" ? 'IN' : 'NOT IN')
|
||||||
va = value.map {|v| v == '0' ? connection.quoted_false : ActiveRecord::Base.connection.quoted_true}.uniq.join(',')
|
va = value.map {|v| v == '0' ? connection.quoted_false : connection.quoted_true}.uniq.join(',')
|
||||||
|
|
||||||
"#{Issue.table_name}.is_private #{op} (#{va})"
|
"#{Issue.table_name}.is_private #{op} (#{va})"
|
||||||
end
|
end
|
||||||
|
@ -460,14 +460,14 @@ class IssueQuery < Query
|
||||||
sql = case operator
|
sql = case operator
|
||||||
when "*", "!*"
|
when "*", "!*"
|
||||||
op = (operator == "*" ? 'IN' : 'NOT IN')
|
op = (operator == "*" ? 'IN' : 'NOT IN')
|
||||||
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name} WHERE #{IssueRelation.table_name}.relation_type = '#{ActiveRecord::Base.connection.quote_string(relation_type)}')"
|
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name} WHERE #{IssueRelation.table_name}.relation_type = '#{connection.quote_string(relation_type)}')"
|
||||||
when "=", "!"
|
when "=", "!"
|
||||||
op = (operator == "=" ? 'IN' : 'NOT IN')
|
op = (operator == "=" ? 'IN' : 'NOT IN')
|
||||||
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name} WHERE #{IssueRelation.table_name}.relation_type = '#{ActiveRecord::Base.connection.quote_string(relation_type)}' AND #{IssueRelation.table_name}.#{target_join_column} = #{value.first.to_i})"
|
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name} WHERE #{IssueRelation.table_name}.relation_type = '#{connection.quote_string(relation_type)}' AND #{IssueRelation.table_name}.#{target_join_column} = #{value.first.to_i})"
|
||||||
when "=p", "=!p", "!p"
|
when "=p", "=!p", "!p"
|
||||||
op = (operator == "!p" ? 'NOT IN' : 'IN')
|
op = (operator == "!p" ? 'NOT IN' : 'IN')
|
||||||
comp = (operator == "=!p" ? '<>' : '=')
|
comp = (operator == "=!p" ? '<>' : '=')
|
||||||
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name}, #{Issue.table_name} relissues WHERE #{IssueRelation.table_name}.relation_type = '#{ActiveRecord::Base.connection.quote_string(relation_type)}' AND #{IssueRelation.table_name}.#{target_join_column} = relissues.id AND relissues.project_id #{comp} #{value.first.to_i})"
|
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name}, #{Issue.table_name} relissues WHERE #{IssueRelation.table_name}.relation_type = '#{connection.quote_string(relation_type)}' AND #{IssueRelation.table_name}.#{target_join_column} = relissues.id AND relissues.project_id #{comp} #{value.first.to_i})"
|
||||||
end
|
end
|
||||||
|
|
||||||
if relation_options[:sym] == field && !options[:reverse]
|
if relation_options[:sym] == field && !options[:reverse]
|
||||||
|
|
|
@ -492,7 +492,7 @@ class Project < ActiveRecord::Base
|
||||||
# Deletes all project's members
|
# Deletes all project's members
|
||||||
def delete_all_members
|
def delete_all_members
|
||||||
me, mr = Member.table_name, MemberRole.table_name
|
me, mr = Member.table_name, MemberRole.table_name
|
||||||
ActiveRecord::Base.connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
|
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
|
||||||
Member.delete_all(['project_id = ?', id])
|
Member.delete_all(['project_id = ?', id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -640,7 +640,7 @@ class Query < ActiveRecord::Base
|
||||||
sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}"
|
sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{ActiveRecord::Base.connection.quote_string(val)}'"}.join(",") + ")"
|
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# IN an empty set
|
# IN an empty set
|
||||||
|
@ -648,7 +648,7 @@ class Query < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
when "!"
|
when "!"
|
||||||
if value.any?
|
if value.any?
|
||||||
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{ActiveRecord::Base.connection.quote_string(val)}'"}.join(",") + "))"
|
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||||
else
|
else
|
||||||
# NOT IN an empty set
|
# NOT IN an empty set
|
||||||
sql = "1=1"
|
sql = "1=1"
|
||||||
|
@ -690,9 +690,9 @@ class Query < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when "o"
|
when "o"
|
||||||
sql = "#{queried_table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{ActiveRecord::Base.connection.quoted_false})" if field == "status_id"
|
sql = "#{queried_table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_false})" if field == "status_id"
|
||||||
when "c"
|
when "c"
|
||||||
sql = "#{queried_table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{ActiveRecord::Base.connection.quoted_true})" if field == "status_id"
|
sql = "#{queried_table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_true})" if field == "status_id"
|
||||||
when "><t-"
|
when "><t-"
|
||||||
# between today - n days and today
|
# between today - n days and today
|
||||||
sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0)
|
sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0)
|
||||||
|
@ -754,9 +754,9 @@ class Query < ActiveRecord::Base
|
||||||
date = Date.today
|
date = Date.today
|
||||||
sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year)
|
sql = date_clause(db_table, db_field, date.beginning_of_year, date.end_of_year)
|
||||||
when "~"
|
when "~"
|
||||||
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{ActiveRecord::Base.connection.quote_string(value.first.to_s.downcase)}%'"
|
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||||
when "!~"
|
when "!~"
|
||||||
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{ActiveRecord::Base.connection.quote_string(value.first.to_s.downcase)}%'"
|
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||||
else
|
else
|
||||||
raise "Unknown query operator #{operator}"
|
raise "Unknown query operator #{operator}"
|
||||||
end
|
end
|
||||||
|
@ -819,7 +819,7 @@ class Query < ActiveRecord::Base
|
||||||
if self.class.default_timezone == :utc
|
if self.class.default_timezone == :utc
|
||||||
from = from.utc
|
from = from.utc
|
||||||
end
|
end
|
||||||
s << ("#{table}.#{field} > '%s'" % [ActiveRecord::Base.connection.quoted_date(from)])
|
s << ("#{table}.#{field} > '%s'" % [connection.quoted_date(from)])
|
||||||
end
|
end
|
||||||
if to
|
if to
|
||||||
if to.is_a?(Date)
|
if to.is_a?(Date)
|
||||||
|
@ -828,7 +828,7 @@ class Query < ActiveRecord::Base
|
||||||
if self.class.default_timezone == :utc
|
if self.class.default_timezone == :utc
|
||||||
to = to.utc
|
to = to.utc
|
||||||
end
|
end
|
||||||
s << ("#{table}.#{field} <= '%s'" % [ActiveRecord::Base.connection.quoted_date(to)])
|
s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date(to)])
|
||||||
end
|
end
|
||||||
s.join(' AND ')
|
s.join(' AND ')
|
||||||
end
|
end
|
||||||
|
|
|
@ -424,10 +424,10 @@ class Repository < ActiveRecord::Base
|
||||||
ci = "#{table_name_prefix}changesets_issues#{table_name_suffix}"
|
ci = "#{table_name_prefix}changesets_issues#{table_name_suffix}"
|
||||||
cp = "#{table_name_prefix}changeset_parents#{table_name_suffix}"
|
cp = "#{table_name_prefix}changeset_parents#{table_name_suffix}"
|
||||||
|
|
||||||
ActiveRecord::Base.connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
||||||
ActiveRecord::Base.connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
||||||
ActiveRecord::Base.connection.delete("DELETE FROM #{cp} WHERE #{cp}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
connection.delete("DELETE FROM #{cp} WHERE #{cp}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
|
||||||
ActiveRecord::Base.connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
|
connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
|
||||||
clear_extra_info_of_changesets
|
clear_extra_info_of_changesets
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue