models: rename post/pool archives to post/pool versions.
This commit is contained in:
@@ -4,7 +4,7 @@ class PoolVersionsController < ApplicationController
|
||||
around_action :set_timeout
|
||||
|
||||
def index
|
||||
@pool_versions = PoolArchive.paginated_search(params)
|
||||
@pool_versions = PoolVersion.paginated_search(params)
|
||||
@pool_versions = @pool_versions.includes(:updater, :pool) if request.format.html?
|
||||
|
||||
respond_with(@pool_versions)
|
||||
@@ -14,10 +14,10 @@ class PoolVersionsController < ApplicationController
|
||||
end
|
||||
|
||||
def diff
|
||||
@pool_version = PoolArchive.find(params[:id])
|
||||
@pool_version = PoolVersion.find(params[:id])
|
||||
|
||||
if params[:other_id]
|
||||
@other_version = PoolArchive.find(params[:other_id])
|
||||
@other_version = PoolVersion.find(params[:other_id])
|
||||
else
|
||||
@other_version = @pool_version.previous
|
||||
end
|
||||
@@ -25,19 +25,15 @@ class PoolVersionsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def model_name
|
||||
"PoolArchive"
|
||||
end
|
||||
|
||||
def set_timeout
|
||||
PoolArchive.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
PoolVersion.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
yield
|
||||
ensure
|
||||
PoolArchive.connection.execute("SET statement_timeout = 0")
|
||||
PoolVersion.connection.execute("SET statement_timeout = 0")
|
||||
end
|
||||
|
||||
def check_availabililty
|
||||
if !PoolArchive.enabled?
|
||||
if !PoolVersion.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class PostVersionsController < ApplicationController
|
||||
respond_to :js, only: [:undo]
|
||||
|
||||
def index
|
||||
@post_versions = PostArchive.paginated_search(params)
|
||||
@post_versions = PostVersion.paginated_search(params)
|
||||
|
||||
if request.format.html?
|
||||
@post_versions = @post_versions.includes(:updater, post: [:uploader, :versions])
|
||||
@@ -21,7 +21,7 @@ class PostVersionsController < ApplicationController
|
||||
end
|
||||
|
||||
def undo
|
||||
@post_version = PostArchive.find(params[:id])
|
||||
@post_version = PostVersion.find(params[:id])
|
||||
@post_version.undo!
|
||||
|
||||
respond_with(@post_version)
|
||||
@@ -29,19 +29,15 @@ class PostVersionsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def model_name
|
||||
"PostArchive"
|
||||
end
|
||||
|
||||
def set_timeout
|
||||
PostArchive.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
PostVersion.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
yield
|
||||
ensure
|
||||
PostArchive.connection.execute("SET statement_timeout = 0")
|
||||
PostVersion.connection.execute("SET statement_timeout = 0")
|
||||
end
|
||||
|
||||
def check_availabililty
|
||||
if !PostArchive.enabled?
|
||||
if !PostVersion.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,9 @@ module Moderator
|
||||
module Queries
|
||||
class Tag < ::Struct.new(:user, :count)
|
||||
def self.all(min_date, max_level)
|
||||
return [] unless PostArchive.enabled?
|
||||
return [] unless PostVersion.enabled?
|
||||
|
||||
records = PostArchive.where("updated_at > ?", min_date).group(:updater).count.map do |user, count|
|
||||
records = PostVersion.where("updated_at > ?", min_date).group(:updater).count.map do |user, count|
|
||||
new(user, count)
|
||||
end
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ module Moderator
|
||||
add_row(sums, Upload.where(uploader_ip_addr: ip_addrs).group(:uploader).count)
|
||||
add_row(sums, Hash[User.where(last_ip_addr: ip_addrs).collect { |user| [user, 1] }])
|
||||
|
||||
add_row_id(sums, PoolArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolArchive.enabled?
|
||||
add_row_id(sums, PostArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostArchive.enabled?
|
||||
add_row_id(sums, PoolVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolVersion.enabled?
|
||||
add_row_id(sums, PostVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostVersion.enabled?
|
||||
|
||||
sums
|
||||
end
|
||||
@@ -50,8 +50,8 @@ module Moderator
|
||||
add_row(sums, ArtistCommentaryVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, ArtistVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, NoteVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, PoolArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolArchive.enabled?
|
||||
add_row(sums, PostArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostArchive.enabled?
|
||||
add_row(sums, PoolVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolVersion.enabled?
|
||||
add_row(sums, PostVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostVersion.enabled?
|
||||
add_row(sums, WikiPageVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, Comment.where(creator: users).group(:creator_ip_addr).count)
|
||||
add_row(sums, Dmail.where(from: users).group(:creator_ip_addr).count)
|
||||
|
||||
@@ -28,9 +28,9 @@ class RelatedTagQuery
|
||||
|
||||
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.
|
||||
def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20)
|
||||
return [] unless user.present? && PostArchive.enabled?
|
||||
return [] unless user.present? && PostVersion.enabled?
|
||||
|
||||
versions = PostArchive.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
versions = PostVersion.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
tags = versions.flat_map(&:added_tags)
|
||||
tags = tags.reject { |tag| Tag.is_metatag?(tag) }
|
||||
tags = tags.group_by(&:itself).transform_values(&:size).sort_by { |tag, count| [-count, tag] }.map(&:first)
|
||||
|
||||
@@ -118,8 +118,8 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def versions
|
||||
if PoolArchive.enabled?
|
||||
PoolArchive.where("pool_id = ?", id).order("id asc")
|
||||
if PoolVersion.enabled?
|
||||
PoolVersion.where("pool_id = ?", id).order("id asc")
|
||||
else
|
||||
raise "Archive service not configured"
|
||||
end
|
||||
@@ -268,8 +268,8 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
if PoolArchive.enabled?
|
||||
PoolArchive.queue(self, updater, updater_ip_addr)
|
||||
if PoolVersion.enabled?
|
||||
PoolVersion.queue(self, updater, updater_ip_addr)
|
||||
else
|
||||
Rails.logger.warn("Archive service is not configured. Pool versions will not be saved.")
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class PoolArchive < ApplicationRecord
|
||||
class PoolVersion < ApplicationRecord
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to :pool
|
||||
|
||||
@@ -7,7 +7,6 @@ class PoolArchive < ApplicationRecord
|
||||
end
|
||||
|
||||
establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
self.table_name = "pool_versions"
|
||||
|
||||
module SearchMethods
|
||||
def default_order
|
||||
@@ -109,7 +108,7 @@ class PoolArchive < ApplicationRecord
|
||||
|
||||
def previous
|
||||
@previous ||= begin
|
||||
PoolArchive.where("pool_id = ? and version < ?", pool_id, version).order("version desc").limit(1).to_a
|
||||
PoolVersion.where("pool_id = ? and version < ?", pool_id, version).order("version desc").limit(1).to_a
|
||||
end
|
||||
@previous.first
|
||||
end
|
||||
@@ -59,8 +59,8 @@ class Post < ApplicationRecord
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :view_count
|
||||
|
||||
if PostArchive.enabled?
|
||||
has_many :versions, -> { Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC") }, :class_name => "PostArchive", :dependent => :destroy
|
||||
if PostVersion.enabled?
|
||||
has_many :versions, -> { Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC") }, class_name: "PostVersion", dependent: :destroy
|
||||
end
|
||||
|
||||
module FileMethods
|
||||
@@ -1307,7 +1307,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def create_new_version
|
||||
User.where(id: CurrentUser.id).update_all("post_update_count = post_update_count + 1")
|
||||
PostArchive.queue(self) if PostArchive.enabled?
|
||||
PostVersion.queue(self) if PostVersion.enabled?
|
||||
end
|
||||
|
||||
def revert_to(target)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class PostArchive < ApplicationRecord
|
||||
class PostVersion < ApplicationRecord
|
||||
class RevertError < StandardError; end
|
||||
extend Memoist
|
||||
|
||||
@@ -10,7 +10,6 @@ class PostArchive < ApplicationRecord
|
||||
end
|
||||
|
||||
establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
self.table_name = "post_versions"
|
||||
|
||||
def self.check_for_retry(msg)
|
||||
if msg =~ /can't get socket descriptor/ && msg =~ /post_versions/
|
||||
@@ -98,7 +97,7 @@ class PostArchive < ApplicationRecord
|
||||
if association(:post).loaded? && post && post.association(:versions).loaded?
|
||||
ver = [post.versions.sort_by(&:version).reverse.find { |v| v.version < version }]
|
||||
else
|
||||
ver = PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").limit(1).to_a
|
||||
ver = PostVersion.where("post_id = ? and version < ?", post_id, version).order("version desc").limit(1).to_a
|
||||
end
|
||||
end
|
||||
@previous.first
|
||||
@@ -107,7 +107,7 @@ class User < ApplicationRecord
|
||||
has_many :post_disapprovals, :dependent => :destroy
|
||||
has_many :post_flags, foreign_key: :creator_id
|
||||
has_many :post_votes
|
||||
has_many :post_versions, class_name: "PostArchive", foreign_key: :updater_id
|
||||
has_many :post_versions, foreign_key: :updater_id
|
||||
has_many :bans, -> {order("bans.id desc")}
|
||||
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
|
||||
|
||||
@@ -587,8 +587,8 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def pool_version_count
|
||||
return nil unless PoolArchive.enabled?
|
||||
PoolArchive.for_user(id).count
|
||||
return nil unless PoolVersion.enabled?
|
||||
PoolVersion.for_user(id).count
|
||||
end
|
||||
|
||||
def forum_post_count
|
||||
|
||||
@@ -116,7 +116,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def pool_version_count(template)
|
||||
if PoolArchive.enabled?
|
||||
if PoolVersion.enabled?
|
||||
template.link_to(user.pool_version_count, template.pool_versions_path(:search => {:updater_id => user.id}))
|
||||
else
|
||||
"N/A"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<% end %>
|
||||
<% t.column "Pool" do |pool_version| %>
|
||||
<%= link_to pool_version.pretty_name, pool_path(pool_version.pool_id), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<%= link_to "»", pool_versions_path(search: { pool_id: pool_version.pool_id }, anchor: "pool-archive-#{pool_version.id}"), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<%= link_to "»", pool_versions_path(search: { pool_id: pool_version.pool_id }, anchor: "pool-version-#{pool_version.id}"), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<% end %>
|
||||
<% t.column "Post Changes", td: { class: "col-expand" } do |pool_version| %>
|
||||
<%= render "pool_versions/diff", diff: pool_version.build_diff %>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<%= subnav_link_to "Delete", pool_path(@pool), :method => :delete, :"data-shortcut" => "shift+d", :"data-confirm" => "Are you sure you want to delete this pool?", :remote => true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<%= subnav_link_to "History", pool_versions_path(:search => {:pool_id => @pool.id}) %>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Version" do |post_version| %>
|
||||
<%= link_to "#{post_version.post_id}.#{post_version.version}", post_versions_path(search: { post_id: post_version.post_id }, anchor: "post-archive-#{post_version.id}") %>
|
||||
<%= link_to "#{post_version.post_id}.#{post_version.version}", post_versions_path(search: { post_id: post_version.post_id }, anchor: "post-version-#{post_version.id}") %>
|
||||
<% end %>
|
||||
<% t.column "Tags", td: {class: "col-expand"} do |post_version| %>
|
||||
<%= post_version_diff(post_version) %>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<% end %>
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
<p class="fineprint">Recent updates may not have been processed yet. The most recently processed version was <%= time_ago_in_words_tagged(PostArchive.maximum(:updated_at)) %>.</p>
|
||||
<p class="fineprint">Recent updates may not have been processed yet. The most recently processed version was <%= time_ago_in_words_tagged(PostVersion.maximum(:updated_at)) %>.</p>
|
||||
|
||||
<% if @post_versions.length == 0 %>
|
||||
<%= render "post_sets/blank" %>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<li><%= link_to_wiki "Help", "help:pools" %></li>
|
||||
<li><%= link_to("Listing", pools_path) %></li>
|
||||
<li><%= link_to("Gallery", gallery_pools_path) %></li>
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<li><%= link_to("Changes", pool_versions_path) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
<td><%= presenter.artist_commentary_version_count(self) %></td>
|
||||
</tr>
|
||||
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<tr>
|
||||
<th>Pool Changes</th>
|
||||
<td><%= presenter.pool_version_count(self) %></td>
|
||||
|
||||
Reference in New Issue
Block a user