summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-12 19:13:25 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-06-12 19:13:25 +0000
commitf9ddb562d58ae98bcc69f74396b028cbc8cce0b1 (patch)
tree8019be9178fb3d14c764c04e3e3a5be955de1385 /app/controllers
parent136cdc765afda57b9be02704e52b27334da42c73 (diff)
downloadredmine-f9ddb562d58ae98bcc69f74396b028cbc8cce0b1.tar.gz
redmine-f9ddb562d58ae98bcc69f74396b028cbc8cce0b1.zip
Cleanup of finders with :conditions option.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11963 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/context_menus_controller.rb3
-rw-r--r--app/controllers/issues_controller.rb2
-rw-r--r--app/controllers/messages_controller.rb2
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/controllers/repositories_controller.rb19
-rw-r--r--app/controllers/sys_controller.rb6
-rw-r--r--app/controllers/users_controller.rb2
-rw-r--r--app/controllers/versions_controller.rb10
8 files changed, 22 insertions, 24 deletions
diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb
index d78ef3d3e..8f6fc1cb4 100644
--- a/app/controllers/context_menus_controller.rb
+++ b/app/controllers/context_menus_controller.rb
@@ -71,8 +71,7 @@ class ContextMenusController < ApplicationController
end
def time_entries
- @time_entries = TimeEntry.all(
- :conditions => {:id => params[:ids]}, :include => :project)
+ @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a
(render_404; return) unless @time_entries.present?
@projects = @time_entries.collect(&:project).compact.uniq
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 327530009..0546db36b 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -301,7 +301,7 @@ class IssuesController < ApplicationController
end
def destroy
- @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
+ @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
if @hours > 0
case params[:todo]
when 'destroy'
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index ad9107639..585101fbd 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -35,7 +35,7 @@ class MessagesController < ApplicationController
page = params[:page]
# Find the page of the requested reply
if params[:r] && page.nil?
- offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
+ offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
page = 1 + offset / REPLIES_PER_PAGE
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 4b1befdd5..968898411 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -155,7 +155,7 @@ class ProjectsController < ApplicationController
@total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
if User.current.allowed_to?(:view_time_entries, @project)
- @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
+ @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f
end
@key = User.current.rss_key
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 0e4f4821f..2db9c3f92 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -352,15 +352,18 @@ class RepositoriesController < ApplicationController
@date_to = Date.today
@date_from = @date_to << 11
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
- commits_by_day = Changeset.count(
- :all, :group => :commit_date,
- :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
+ commits_by_day = Changeset.
+ where("repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to).
+ group(:commit_date).
+ count
commits_by_month = [0] * 12
commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
- changes_by_day = Change.count(
- :all, :group => :commit_date, :include => :changeset,
- :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
+ changes_by_day = Change.
+ joins(:changeset).
+ where("#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to).
+ group(:commit_date).
+ count
changes_by_month = [0] * 12
changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
@@ -393,10 +396,10 @@ class RepositoriesController < ApplicationController
end
def graph_commits_per_author(repository)
- commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
+ commits_by_author = Changeset.where("repository_id = ?", repository.id).group(:committer).count
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
- changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
+ changes_by_author = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", repository.id).group(:committer).count
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
fields = commits_by_author.collect {|r| r.first}
diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb
index b822c5c1e..295f6c030 100644
--- a/app/controllers/sys_controller.rb
+++ b/app/controllers/sys_controller.rb
@@ -19,11 +19,7 @@ class SysController < ActionController::Base
before_filter :check_enabled
def projects
- p = Project.active.has_module(:repository).find(
- :all,
- :include => :repository,
- :order => "#{Project.table_name}.identifier"
- )
+ p = Project.active.has_module(:repository).order("#{Project.table_name}.identifier").preload(:repository).all
# extra_info attribute from repository breaks activeresource client
render :xml => p.to_xml(
:only => [:id, :identifier, :name, :is_public, :status],
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3ea65c7aa..4d89e04f5 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -60,7 +60,7 @@ class UsersController < ApplicationController
def show
# show projects based on current user visibility
- @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
+ @memberships = @user.memberships.where(Project.visible_condition(User.current)).all
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
@events_by_day = events.group_by(&:event_date)
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index f159f7ecc..aa5beb0f9 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -46,11 +46,11 @@ class VersionsController < ApplicationController
@issues_by_version = {}
if @selected_tracker_ids.any? && @versions.any?
- issues = Issue.visible.all(
- :include => [:project, :status, :tracker, :priority, :fixed_version],
- :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
- :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
- )
+ issues = Issue.visible.
+ includes(:project, :tracker).
+ preload(:status, :priority, :fixed_version).
+ where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
+ order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
@issues_by_version = issues.group_by(&:fixed_version)
end
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}