models: rename post/pool archives to post/pool versions.

This commit is contained in:
evazion
2020-02-15 06:52:10 -06:00
parent 51f3f7338a
commit 60ff2ae929
27 changed files with 71 additions and 84 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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