Implement forum topic voting and tag change pruning (#3580)

This commit is contained in:
Albert Yi
2018-04-16 16:09:39 -07:00
parent 45fad069d7
commit f2b525a6d2
182 changed files with 558 additions and 554 deletions

View File

@@ -5,6 +5,7 @@ class DailyMaintenance
TagPruner.new.prune!
Upload.where('created_at < ?', 1.day.ago).delete_all
Delayed::Job.where('created_at < ?', 45.days.ago).delete_all
#ForumPostVote.where("created_at < ?", 90.days.ago).delete_all
PostVote.prune!
CommentVote.prune!
ApiCacheGenerator.new.generate_tag_cache
@@ -15,5 +16,7 @@ class DailyMaintenance
Tag.clean_up_negative_post_counts!
SuperVoter.init!
TokenBucket.prune!
TagChangeRequestPruner.warn_all
TagChangeRequestPruner.reject_all
end
end

View File

@@ -79,7 +79,8 @@ private
end
def load_session_user
CurrentUser.user = User.find_by_id(session[:user_id])
user = User.find_by_id(session[:user_id])
CurrentUser.user = user if user
end
def load_cookie_user

View File

@@ -0,0 +1,43 @@
# Service to prune old unapproved tag change requests
# (including tag aliases, tag implications, and bulk
# update requests).
class TagChangeRequestPruner
def self.warn_all
[TagAlias, TagImplication, BulkUpdateRequest].each do |model|
new.warn_old(model)
end
end
def self.reject_all
[TagAlias, TagImplication, BulkUpdateRequest].each do |model|
new.reject_expired(model)
end
end
def warn_old(model)
model.old.pending.find_each do |tag_change|
if tag_change.forum_topic
name = model.model_name.human.downcase
body = "This #{name} is pending automatic rejection in 5 days."
unless tag_change.forum_topic.posts.where(creator_id: User.system.id, body: body).exists?
tag_change.forum_updater.update(body)
end
end
end
end
def reject_expired(model)
model.expired.pending.find_each do |tag_change|
if tag_change.forum_topic
name = model.model_name.human.downcase
body = "This #{name} has been rejected because it was not approved within 60 days."
tag_change.forum_updater.update(body)
end
CurrentUser.as_system do
tag_change.reject!
end
end
end
end