forked from e621ng/e621ng
Merge pull request #2912 from evazion/opt-post-archive
Fix N+1 queries issues on /post_versions
This commit is contained in:
commit
34a26d71db
@ -3,7 +3,7 @@ class PostVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@post_versions = PostArchive.search(params[:search]).order("updated_at desc, id desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
@post_versions = PostArchive.includes(:post, :updater).search(params[:search]).order("updated_at desc, id desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
respond_with(@post_versions) do |format|
|
||||
format.xml do
|
||||
render :xml => @post_versions.to_xml(:root => "post-versions")
|
||||
|
@ -1,6 +1,9 @@
|
||||
class PostArchive < ActiveRecord::Base
|
||||
extend Memoist
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :updater, class_name: "User"
|
||||
|
||||
def self.enabled?
|
||||
Danbooru.config.aws_sqs_archives_url.present?
|
||||
end
|
||||
@ -92,18 +95,10 @@ class PostArchive < ActiveRecord::Base
|
||||
super
|
||||
end
|
||||
|
||||
def post
|
||||
Post.where(id: post_id).first
|
||||
end
|
||||
|
||||
def previous
|
||||
PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").first
|
||||
end
|
||||
|
||||
def updater
|
||||
User.find(updater_id)
|
||||
end
|
||||
|
||||
def diff(version = nil)
|
||||
if post.nil?
|
||||
latest_tags = tag_array
|
||||
@ -237,13 +232,9 @@ class PostArchive < ActiveRecord::Base
|
||||
post.save!
|
||||
end
|
||||
|
||||
def updater
|
||||
User.find_by_id(updater_id)
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags, :updater_name]
|
||||
end
|
||||
|
||||
memoize :previous, :post, :tag_array, :changes, :added_tags_with_fields, :removed_tags_with_fields, :obsolete_removed_tags, :obsolete_added_tags, :unchanged_tags
|
||||
memoize :previous, :tag_array, :changes, :added_tags_with_fields, :removed_tags_with_fields, :obsolete_removed_tags, :obsolete_added_tags, :unchanged_tags
|
||||
end
|
||||
|
@ -37,7 +37,7 @@
|
||||
<% if CurrentUser.is_member? %>
|
||||
<td>
|
||||
<% if post_version.post.visible? %>
|
||||
<% if post_version.id != post_version.post.versions.first.id %>
|
||||
<% if post_version.version != 1 %>
|
||||
<%= link_to "Undo", undo_post_version_path(post_version), :method => :put, :remote => true %> |
|
||||
<% end %>
|
||||
<%= link_to "Revert to", revert_post_path(post_version.post_id, :version_id => post_version.id), :method => :put, :remote => true %>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div id="a-index">
|
||||
<h1>Changes</h1>
|
||||
|
||||
<% if @post_versions.empty? %>
|
||||
<% if @post_versions.length == 0 %>
|
||||
<%= render "post_sets/blank" %>
|
||||
<% else %>
|
||||
<%= render "listing", :post_versions => @post_versions %>
|
||||
|
Loading…
Reference in New Issue
Block a user