From 0e3b8fbb24095d61e7dfb1f3573f996d82a19d1f Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Mon, 22 Jul 2013 20:44:11 +0200 Subject: [PATCH] Remove some calls to `all`. They are not required, and Rails4 raises warnings about them. --- app/controllers/admin/email_controller.rb | 2 +- app/controllers/admin/groups_controller.rb | 2 +- app/controllers/notifications_controller.rb | 4 ++-- app/controllers/post_actions_controller.rb | 2 +- app/models/category.rb | 2 +- app/models/post_action.rb | 2 +- app/models/post_action_type.rb | 2 +- app/models/topic.rb | 1 - spec/models/user_spec.rb | 2 +- 9 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index f7f1f3e21fa..9450a448e68 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -16,7 +16,7 @@ class Admin::EmailController < Admin::AdminController end def logs - @email_logs = EmailLog.limit(50).includes(:user).order('created_at desc').all + @email_logs = EmailLog.limit(50).includes(:user).order('created_at desc').to_a render_serialized(@email_logs, EmailLogSerializer) end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 40026b6d014..5195cea9b51 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,6 +1,6 @@ class Admin::GroupsController < Admin::AdminController def index - groups = Group.order(:name).all + groups = Group.order(:name).to_a render_serialized(groups, BasicGroupSerializer) end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index dc0b5e4470a..9f4ddd6f91f 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -3,7 +3,7 @@ class NotificationsController < ApplicationController before_filter :ensure_logged_in def index - notifications = current_user.notifications.recent.includes(:topic).all.to_a + notifications = current_user.notifications.recent.includes(:topic) if notifications.present? notifications += current_user.notifications @@ -11,9 +11,9 @@ class NotificationsController < ApplicationController .where(read: false, notification_type: Notification.types[:private_message]) .where('id < ?', notifications.last.id) .limit(5) - .to_a end + notifications = notifications.to_a current_user.saw_notification_id(notifications.first.id) if notifications.present? current_user.reload current_user.publish_notifications_state diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index 5174a1800d1..f382f326c4e 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -31,7 +31,7 @@ class PostActionsController < ApplicationController users = User.select(['null as post_url','users.id', 'users.username', 'users.username_lower', 'users.email','post_actions.related_post_id']) .joins(:post_actions) .where(['post_actions.post_id = ? and post_actions.post_action_type_id = ? and post_actions.deleted_at IS NULL', @post.id, @post_action_type_id]) - .all + .to_a urls = Post.urls(users.map{|u| u.related_post_id}) users.each do |u| diff --git a/app/models/category.rb b/app/models/category.rb index 20f971f8df4..b055770d5c6 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -140,7 +140,7 @@ class Category < ActiveRecord::Base end def publish_categories_list - MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest.all).as_json}) + MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json}) end def uncategorized_validator diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 9938cddee6e..979941f388d 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -345,7 +345,7 @@ class PostAction < ActiveRecord::Base # TODO add serializer so we can skip this posts.map!(&:marshal_dump) - [posts, User.select([:id, :username, :email]).where(id: users.to_a).all] + [posts, User.select([:id, :username, :email]).where(id: users.to_a).to_a] end protected diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb index 542cc04eae3..96c42945fee 100644 --- a/app/models/post_action_type.rb +++ b/app/models/post_action_type.rb @@ -3,7 +3,7 @@ require_dependency 'enum' class PostActionType < ActiveRecord::Base class << self def ordered - order('position asc').all + order('position asc') end def types diff --git a/app/models/topic.rb b/app/models/topic.rb index 793cfef2307..d967d28907f 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -253,7 +253,6 @@ class Topic < ActiveRecord::Base .listable_topics .limit(SiteSetting.max_similar_results) .order('similarity desc') - .all end def update_status(status, enabled, user) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7b286a481e9..e5d5a2fef35 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -223,7 +223,7 @@ describe User do it 'allows moderator to delete all posts' do @user.delete_all_posts!(@guardian) - expect(Post.where(id: @posts.map(&:id)).all).to be_empty + expect(Post.where(id: @posts.map(&:id))).to be_empty @posts.each do |p| if p.post_number == 1 expect(Topic.where(id: p.topic_id).first).to be_nil