post versions: add more search options to /post_versions/search.

This commit is contained in:
evazion
2019-09-26 16:35:05 -05:00
parent 3341223b40
commit 12de26d2cf
3 changed files with 12 additions and 28 deletions

View File

@@ -18,36 +18,12 @@ class PostArchive < ApplicationRecord
end
module SearchMethods
def for_user(user_id)
if user_id
where("updater_id = ?", user_id)
else
none
end
end
def for_user_name(name)
user_id = User.name_to_id(name)
for_user(user_id)
end
def search(params)
q = super
q = q.search_attributes(params, :updater_id, :post_id, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version)
if params[:updater_name].present?
q = q.for_user_name(params[:updater_name])
end
if params[:updater_id].present?
q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i))
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end
if params[:start_id].present?
q = q.where("id <= ?", params[:start_id].to_i)
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
end
q.apply_default_order(params)

View File

@@ -97,7 +97,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_archives
has_many :post_versions, class_name: "PostArchive", foreign_key: :updater_id
has_many :bans, -> {order("bans.id desc")}
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
@@ -668,7 +668,7 @@ class User < ApplicationRecord
self.class.without_timeout do
User.where(id: id).update_all(
post_upload_count: posts.count,
post_update_count: PostArchive.for_user(id).count,
post_update_count: post_versions.count,
note_update_count: note_versions.count
)
end