Replaces find(:first/:all) calls.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10931 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-03 21:30:10 +00:00
parent a7023dfa9b
commit ea296a109a
12 changed files with 56 additions and 45 deletions

View File

@ -32,10 +32,9 @@ class AdminController < ApplicationController
def projects
@status = params[:status] || 1
scope = Project.status(@status)
scope = Project.status(@status).order('lft')
scope = scope.like(params[:name]) if params[:name].present?
@projects = scope.all(:order => 'lft')
@projects = scope.all
render :action => "projects", :layout => false if request.xhr?
end

View File

@ -43,17 +43,22 @@ class BoardsController < ApplicationController
@topic_count = @board.topics.count
@topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC").order(sort_clause).all(
:include => [:author, {:last_reply => :author}],
:limit => @topic_pages.items_per_page,
:offset => @topic_pages.current.offset)
@topics = @board.topics.
reorder("#{Message.table_name}.sticky DESC").
includes(:author, {:last_reply => :author}).
limit(@topic_pages.items_per_page).
offset(@topic_pages.current.offset).
order(sort_clause).
all
@message = Message.new(:board => @board)
render :action => 'show', :layout => !request.xhr?
}
format.atom {
@messages = @board.messages.find :all, :order => 'created_on DESC',
:include => [:author, :board],
:limit => Setting.feeds_limit.to_i
@messages = @board.messages.
reorder('created_on DESC').
includes(:author, :board).
limit(Setting.feeds_limit.to_i).
all
render_feed(@messages, :title => "#{@project}: #{@board}")
}
end

View File

@ -27,7 +27,7 @@ class DocumentsController < ApplicationController
def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
documents = @project.documents.find :all, :include => [:attachments, :category]
documents = @project.documents.includes(:attachments, :category).all
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.updated_on.to_date }

View File

@ -36,7 +36,7 @@ class TrackersController < ApplicationController
def new
@tracker ||= Tracker.new(params[:tracker])
@trackers = Tracker.find :all, :order => 'position'
@trackers = Tracker.sorted.all
@projects = Project.all
end

View File

@ -47,10 +47,7 @@ class UsersController < ApplicationController
@user_count = scope.count
@user_pages = Paginator.new self, @user_count, @limit, params['page']
@offset ||= @user_pages.current.offset
@users = scope.find :all,
:order => sort_clause,
:limit => @limit,
:offset => @offset
@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
respond_to do |format|
format.html {

View File

@ -213,11 +213,12 @@ class WikiController < ApplicationController
@version_count = @page.content.versions.count
@version_pages = Paginator.new self, @version_count, per_page_option, params['page']
# don't load text
@versions = @page.content.versions.find :all,
:select => "id, author_id, comments, updated_on, version",
:order => 'version DESC',
:limit => @version_pages.items_per_page + 1,
:offset => @version_pages.current.offset
@versions = @page.content.versions.
select("id, author_id, comments, updated_on, version").
reorder('version DESC').
limit(@version_pages.items_per_page + 1).
offset(@version_pages.current.offset).
all
render :layout => false if request.xhr?
end

View File

@ -685,12 +685,14 @@ class Query < ActiveRecord::Base
order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
order_option = nil if order_option.blank?
issues = Issue.visible.scoped(:conditions => options[:conditions]).find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
issues = Issue.visible.where(options[:conditions]).all(
:include => ([:status, :project] + (options[:include] || [])).uniq,
:conditions => statement,
:order => order_option,
:joins => joins_for_order_statement(order_option),
:limit => options[:limit],
:offset => options[:offset]
)
if has_column?(:spent_hours)
Issue.load_visible_spent_hours(issues)
@ -721,11 +723,13 @@ class Query < ActiveRecord::Base
# Returns the journals
# Valid options are :order, :offset, :limit
def journals(options={})
Journal.visible.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
Journal.visible.all(
:include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
:conditions => statement,
:order => options[:order],
:limit => options[:limit],
:offset => options[:offset]
)
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end
@ -733,7 +737,10 @@ class Query < ActiveRecord::Base
# Returns the versions
# Valid options are :conditions
def versions(options={})
Version.visible.scoped(:conditions => options[:conditions]).find :all, :include => :project, :conditions => project_statement
Version.visible.where(options[:conditions]).all(
:include => :project,
:conditions => project_statement
)
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end

View File

@ -248,14 +248,16 @@ module ActiveRecord #:nodoc:
def self.reloadable? ; false ; end
# find first version before the given version
def self.before(version)
find :first, :order => 'version desc',
:conditions => ["#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version]
order('version desc').
where("#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version).
first
end
# find first version after the given version.
def self.after(version)
find :first, :order => 'version',
:conditions => ["#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version]
order('version').
where("#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version).
first
end
def previous
@ -467,9 +469,9 @@ module ActiveRecord #:nodoc:
# Finds versions of a specific model. Takes an options hash like <tt>find</tt>
def find_versions(id, options = {})
versioned_class.find :all, {
versioned_class.all({
:conditions => ["#{versioned_foreign_key} = ?", id],
:order => 'version' }.merge(options)
:order => 'version' }.merge(options))
end
# Returns an array of columns that are versioned. See non_versioned_columns

View File

@ -30,7 +30,7 @@ task :migrate_from_mantis => :environment do
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {10 => DEFAULT_STATUS, # new
20 => feedback_status, # feedback
30 => DEFAULT_STATUS, # acknowledged
@ -347,7 +347,7 @@ task :migrate_from_mantis => :environment do
bug.bug_files.each do |file|
a = Attachment.new :created_on => file.date_added
a.file = file
a.author = User.find :first
a.author = User.first
a.container = i
a.save
end

View File

@ -30,7 +30,7 @@ namespace :redmine do
assigned_status = IssueStatus.find_by_position(2)
resolved_status = IssueStatus.find_by_position(3)
feedback_status = IssueStatus.find_by_position(4)
closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
closed_status = IssueStatus.where(:is_closed => true).first
STATUS_MAPPING = {'new' => DEFAULT_STATUS,
'reopened' => feedback_status,
'assigned' => assigned_status,

View File

@ -45,7 +45,7 @@ class AccountTest < ActionController::IntegrationTest
# User logs in with 'autologin' checked
post '/login', :username => user.login, :password => 'admin', :autologin => 1
assert_redirected_to '/my/page'
token = Token.find :first
token = Token.first
assert_not_nil token
assert_equal user, token.user
assert_equal 'autologin', token.action

View File

@ -877,7 +877,7 @@ class IssueTest < ActiveSupport::TestCase
# Closing issue 1
issue1.init_journal(User.first, "Closing issue1")
issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
issue1.status = IssueStatus.where(:is_closed => true).first
assert issue1.save
# 2 and 3 should be also closed
assert issue2.reload.closed?
@ -896,7 +896,7 @@ class IssueTest < ActiveSupport::TestCase
# Closing issue 2
issue2.init_journal(User.first, "Closing issue2")
issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true}
issue2.status = IssueStatus.where(:is_closed => true).first
assert issue2.save
# 1 should not be also closed
assert !issue1.reload.closed?