performance tweaks for rails 4.1

This commit is contained in:
r888888888
2014-04-24 22:18:14 -07:00
parent a89c57cee0
commit aab03422bc
16 changed files with 22 additions and 16 deletions

View File

@@ -51,5 +51,6 @@ end
group :development do group :development do
gem 'ruby-prof' gem 'ruby-prof'
gem 'sql-logging'
end end

View File

@@ -183,6 +183,8 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sql-logging (3.0.8)
rails (> 3.0.0)
statistics2 (0.54) statistics2 (0.54)
term-ansicolor (1.3.0) term-ansicolor (1.3.0)
tins (~> 1.0) tins (~> 1.0)
@@ -253,6 +255,7 @@ DEPENDENCIES
shoulda shoulda
simple_form simple_form
simplecov simplecov
sql-logging
statistics2 statistics2
term-ansicolor term-ansicolor
therubyracer therubyracer

View File

@@ -13,7 +13,7 @@ class AdvertisementsController < ApplicationController
end end
def index def index
@advertisements = Advertisement.order("id desc").all @advertisements = Advertisement.order("id desc")
@start_date = 1.month.ago.to_date @start_date = 1.month.ago.to_date
@end_date = Date.today @end_date = Date.today
end end

View File

@@ -79,7 +79,7 @@ private
def index_by_post def index_by_post
@posts = Post.where("last_comment_bumped_at IS NOT NULL").tag_match(params[:tags]).reorder("last_comment_bumped_at DESC").paginate(params[:page], :limit => 5, :search_count => params[:search]) @posts = Post.where("last_comment_bumped_at IS NOT NULL").tag_match(params[:tags]).reorder("last_comment_bumped_at DESC").paginate(params[:page], :limit => 5, :search_count => params[:search])
@posts.all @posts.each # hack to force rails to eager load
respond_with(@posts) do |format| respond_with(@posts) do |format|
format.html {render :action => "index_by_post"} format.html {render :action => "index_by_post"}
format.xml do format.xml do

View File

@@ -31,7 +31,7 @@ class ForumTopicsController < ApplicationController
def show def show
@forum_topic = ForumTopic.find(params[:id]) @forum_topic = ForumTopic.find(params[:id])
@forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) @forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page])
@forum_posts.all @forum_posts.each # hack to force rails to eager load
respond_with(@forum_topic) respond_with(@forum_topic)
unless CurrentUser.user.is_anonymous? unless CurrentUser.user.is_anonymous?
session[:read_forum_topics] = @forum_topic.mark_as_read(read_forum_topic_ids) session[:read_forum_topics] = @forum_topic.mark_as_read(read_forum_topic_ids)

View File

@@ -7,7 +7,7 @@ module Moderator
def show def show
::Post.without_timeout do ::Post.without_timeout do
@posts = ::Post.order("posts.id asc").pending_or_flagged.available_for_moderation(params[:hidden]).search(:tag_match => "#{params[:query]} status:any").paginate(params[:page], :limit => 100) @posts = ::Post.order("posts.id asc").pending_or_flagged.available_for_moderation(params[:hidden]).search(:tag_match => "#{params[:query]} status:any").paginate(params[:page], :limit => 100)
@posts.all # cache the data @posts.each # hack to force rails to eager load
end end
respond_with(@posts) respond_with(@posts)
end end

View File

@@ -22,7 +22,9 @@ class PoolElementsController < ApplicationController
end end
def all_select def all_select
@pools = Pool.undeleted.where("is_active = true").order("name").select("id, name").all @pools = Pool.undeleted.where("is_active = true").order("name").select("id, name")
@pools.each # hack to force rails to eager load
@pools
end end
private private

View File

@@ -7,7 +7,7 @@ module PostSets
def posts def posts
@posts ||= begin @posts ||= begin
temp = ::Post.tag_match("#{tag_string} favcount:>3").paginate(page, :search_count => nil, :limit => 5) temp = ::Post.tag_match("#{tag_string} favcount:>3").paginate(page, :search_count => nil, :limit => 5)
temp.all temp.each # hack to force rails to eager load
temp temp
end end
end end

View File

@@ -73,7 +73,7 @@ module PostSets
else else
temp = ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page) temp = ::Post.tag_match(tag_string).paginate(page, :count => ::Post.fast_count(tag_string), :limit => per_page)
end end
temp.all temp.each # hack to force rails to eager load
temp temp
end end
end end

View File

@@ -4,7 +4,7 @@ require 'mail'
class UploadErrorChecker class UploadErrorChecker
def check! def check!
uploads = Upload.where("status like 'error%' and status not like 'error: RuntimeError - duplicate%' and created_at >= ?", 1.hour.ago).all uploads = Upload.where("status like 'error%' and status not like 'error: RuntimeError - duplicate%' and created_at >= ?", 1.hour.ago)
if uploads.size > 5 if uploads.size > 5
mail = Mail.new do mail = Mail.new do
from "webmaster@danbooru.donmai.us" from "webmaster@danbooru.donmai.us"

View File

@@ -66,7 +66,7 @@ class PostVersion < ActiveRecord::Base
end end
def sequence_for_post def sequence_for_post
versions = PostVersion.where(:post_id => post_id).order("updated_at desc, id desc").all versions = PostVersion.where(:post_id => post_id).order("updated_at desc, id desc")
diffs = [] diffs = []
versions.each_index do |i| versions.each_index do |i|
if i < versions.size - 1 if i < versions.size - 1

View File

@@ -607,7 +607,7 @@ class Tag < ActiveRecord::Base
search_for = "%" + query.to_escaped_for_sql_like + "%" search_for = "%" + query.to_escaped_for_sql_like + "%"
end end
Tag.where(["name LIKE ? ESCAPE E'\\\\' AND post_count > 0 AND name <> ?", search_for, query]).all(:order => "post_count DESC", :limit => 6, :select => "name").map(&:name).sort Tag.where(["name LIKE ? ESCAPE E'\\\\' AND post_count > 0 AND name <> ?", search_for, query]).order("post_count DESC").limit(6).select("name").map(&:name).sort
end end
end end

View File

@@ -29,7 +29,7 @@ class TagImplication < ActiveRecord::Base
until children.empty? until children.empty?
all.concat(children) all.concat(children)
children = TagImplication.where("antecedent_name IN (?) and status in (?)", children, ["active", "processing"]).all.map(&:consequent_name) children = TagImplication.where("antecedent_name IN (?) and status in (?)", children, ["active", "processing"]).map(&:consequent_name)
end end
end.sort.uniq end.sort.uniq
end end

View File

@@ -32,7 +32,7 @@ class UserNameChangeRequest < ActiveRecord::Base
end end
def feedback def feedback
UserFeedback.for_user(user_id).order("id desc").all UserFeedback.for_user(user_id).order("id desc")
end end
def notify_admins def notify_admins

View File

@@ -14,7 +14,7 @@ class WikiPagePresenter
end end
def consequent_tag_aliases def consequent_tag_aliases
@consequent_tag_aliases ||= TagAlias.where("status = 'active' and consequent_name = ?", wiki_page.title).all @consequent_tag_aliases ||= TagAlias.where("status = 'active' and consequent_name = ?", wiki_page.title)
end end
def antecedent_tag_alias def antecedent_tag_alias
@@ -22,11 +22,11 @@ class WikiPagePresenter
end end
def consequent_tag_implications def consequent_tag_implications
@consequent_tag_implications ||= TagImplication.where("status = 'active' and consequent_name = ?", wiki_page.title).all @consequent_tag_implications ||= TagImplication.where("status = 'active' and consequent_name = ?", wiki_page.title)
end end
def antecedent_tag_implications def antecedent_tag_implications
@antecedent_tag_implications ||= TagImplication.where("status = 'active' and antecedent_name = ?", wiki_page.title).all @antecedent_tag_implications ||= TagImplication.where("status = 'active' and antecedent_name = ?", wiki_page.title)
end end
# Produce a formatted page that shows the difference between two versions of a page. # Produce a formatted page that shows the difference between two versions of a page.

View File

@@ -2,7 +2,7 @@
<div id="a-index"> <div id="a-index">
<h1>Changes</h1> <h1>Changes</h1>
<% if @post_versions.all.empty? %> <% if @post_versions.empty? %>
<%= render "post_sets/blank" %> <%= render "post_sets/blank" %>
<% else %> <% else %>
<%= render "listing", :post_versions => @post_versions %> <%= render "listing", :post_versions => @post_versions %>