2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-28 12:02:59 -05:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
# This job will run on a regular basis to update statistics and denormalized data.
|
|
|
|
# If it does not run, the site will not function properly.
|
2019-10-01 23:01:53 -05:00
|
|
|
class PeriodicalUpdates < ::Jobs::Scheduled
|
2014-02-05 17:14:41 -06:00
|
|
|
every 15.minutes
|
2013-03-28 12:02:59 -05:00
|
|
|
|
2016-07-21 18:48:26 -05:00
|
|
|
def self.should_update_long_topics?
|
|
|
|
@call_count ||= 0
|
|
|
|
@call_count += 1
|
|
|
|
|
|
|
|
# once every 6 hours
|
|
|
|
(@call_count % 24) == 1
|
|
|
|
end
|
|
|
|
|
2019-01-08 15:57:20 -06:00
|
|
|
def execute(args = nil)
|
2013-03-28 12:02:59 -05:00
|
|
|
# Feature topics in categories
|
2017-12-19 20:42:29 -06:00
|
|
|
CategoryFeaturedTopic.feature_topics(batched: true)
|
2013-03-28 12:02:59 -05:00
|
|
|
|
|
|
|
# Update the scores of posts
|
2017-07-27 20:20:09 -05:00
|
|
|
args = { min_topic_age: 1.day.ago }
|
2016-07-21 18:48:26 -05:00
|
|
|
args[:max_topic_length] = 500 unless self.class.should_update_long_topics?
|
|
|
|
ScoreCalculator.new.calculate(args)
|
2013-12-23 17:50:36 -06:00
|
|
|
|
2014-05-28 01:54:21 -05:00
|
|
|
# Forces rebake of old posts where needed, as long as no system avatars need updating
|
2018-12-07 00:03:22 -06:00
|
|
|
if !SiteSetting.automatically_download_gravatars || !UserAvatar.where("last_gravatar_download_attempt IS NULL").limit(1).first
|
2019-01-16 21:53:09 -06:00
|
|
|
problems = Post.rebake_old(SiteSetting.rebake_old_posts_count, priority: :ultra_low)
|
2014-07-17 15:22:46 -05:00
|
|
|
problems.each do |hash|
|
2015-06-12 05:02:36 -05:00
|
|
|
post_id = hash[:post].id
|
|
|
|
Discourse.handle_job_exception(hash[:ex], error_context(args, "Rebaking post id #{post_id}", post_id: post_id))
|
2014-07-17 15:22:46 -05:00
|
|
|
end
|
2014-05-28 01:54:21 -05:00
|
|
|
end
|
2014-06-24 02:10:56 -05:00
|
|
|
|
2014-08-05 01:37:56 -05:00
|
|
|
# rebake out of date user profiles
|
|
|
|
problems = UserProfile.rebake_old(250)
|
|
|
|
problems.each do |hash|
|
|
|
|
user_id = hash[:profile].user_id
|
2015-02-09 14:47:46 -06:00
|
|
|
Discourse.handle_job_exception(hash[:ex], error_context(args, "Rebaking user id #{user_id}", user_id: user_id))
|
2014-08-05 01:37:56 -05:00
|
|
|
end
|
2015-09-06 20:57:50 -05:00
|
|
|
|
2015-10-01 02:17:15 -05:00
|
|
|
offset = (SiteSetting.max_new_topics).to_i
|
2015-09-06 20:57:50 -05:00
|
|
|
last_new_topic = Topic.order('created_at desc').offset(offset).select(:created_at).first
|
|
|
|
if last_new_topic
|
|
|
|
SiteSetting.min_new_topics_time = last_new_topic.created_at.to_i
|
|
|
|
end
|
|
|
|
|
2018-07-16 18:33:33 -05:00
|
|
|
Category.auto_bump_topic!
|
2018-07-16 03:10:22 -05:00
|
|
|
|
2015-09-06 20:57:50 -05:00
|
|
|
nil
|
2013-03-28 12:02:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|