Replaces find(:first) calls.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10928 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-12-03 18:21:32 +00:00
parent 013c6fe009
commit 31c33f462d
31 changed files with 101 additions and 96 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ class Document < ActiveRecord::Base
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
:author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => :project}
+1 -1
View File
@@ -355,7 +355,7 @@ class MailHandler < ActionMailer::Base
}.delete_if {|k, v| v.blank? }
if issue.new_record? && attrs['tracker_id'].nil?
attrs['tracker_id'] = issue.project.trackers.find(:first).try(:id)
attrs['tracker_id'] = issue.project.trackers.first.try(:id)
end
attrs
+7 -4
View File
@@ -308,9 +308,12 @@ class Project < ActiveRecord::Base
# Check that there is no issue of a non descendant project that is assigned
# to one of the project or descendant versions
v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten
if v_ids.any? && Issue.find(:first, :include => :project,
:conditions => ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" +
" AND #{Issue.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids])
if v_ids.any? &&
Issue.
includes(:project).
where("#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?", lft, rgt).
where("#{Issue.table_name}.fixed_version_id IN (?)", v_ids).
exists?
return false
end
Project.transaction do
@@ -655,7 +658,7 @@ class Project < ActiveRecord::Base
# Returns an auto-generated project identifier based on the last identifier used
def self.next_identifier
p = Project.find(:first, :order => 'created_on DESC')
p = Project.order('created_on DESC').first
p.nil? ? nil : p.identifier.to_s.succ
end
+7 -4
View File
@@ -234,12 +234,15 @@ class Repository < ActiveRecord::Base
def find_changeset_by_name(name)
return nil if name.blank?
s = name.to_s
changesets.find(:first, :conditions => (s.match(/^\d*$/) ?
["revision = ?", s] : ["revision LIKE ?", s + '%']))
if s.match(/^\d*$/)
changesets.where("revision = ?", s).first
else
changesets.where("revision LIKE ?", s + '%').first
end
end
def latest_changeset
@latest_changeset ||= changesets.find(:first)
@latest_changeset ||= changesets.first
end
# Returns the latest changesets for +path+
@@ -301,7 +304,7 @@ class Repository < ActiveRecord::Base
return @found_committer_users[committer] if @found_committer_users.has_key?(committer)
user = nil
c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user)
c = changesets.where(:committer => committer).includes(:user).first
if c && c.user
user = c.user
elsif committer.strip =~ /^([^<]+)(<(.*)>)?$/
+1 -1
View File
@@ -686,7 +686,7 @@ class AnonymousUser < User
def validate_anonymous_uniqueness
# There should be only one AnonymousUser in the database
errors.add :base, 'An anonymous user already exists.' if AnonymousUser.find(:first)
errors.add :base, 'An anonymous user already exists.' if AnonymousUser.exists?
end
def available_custom_fields