2013-03-28 13:02:59 -04:00
|
|
|
require_dependency 'score_calculator'
|
|
|
|
|
|
|
|
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.
|
2013-08-07 13:25:05 -04:00
|
|
|
class PeriodicalUpdates < Jobs::Scheduled
|
2014-02-05 18:14:41 -05:00
|
|
|
every 15.minutes
|
2013-03-28 13:02:59 -04:00
|
|
|
|
2016-07-21 19:48:26 -04:00
|
|
|
def self.should_update_long_topics?
|
|
|
|
@call_count ||= 0
|
|
|
|
@call_count += 1
|
|
|
|
|
|
|
|
# once every 6 hours
|
|
|
|
(@call_count % 24) == 1
|
|
|
|
end
|
|
|
|
|
2013-03-28 13:02:59 -04:00
|
|
|
def execute(args)
|
|
|
|
# Feature topics in categories
|
|
|
|
CategoryFeaturedTopic.feature_topics
|
|
|
|
|
|
|
|
# Update the scores of posts
|
2017-07-27 21:20:09 -04:00
|
|
|
args = { min_topic_age: 1.day.ago }
|
2016-07-21 19:48:26 -04:00
|
|
|
args[:max_topic_length] = 500 unless self.class.should_update_long_topics?
|
|
|
|
ScoreCalculator.new.calculate(args)
|
2013-12-23 18:50:36 -05:00
|
|
|
|
2017-03-21 23:12:02 -04:00
|
|
|
# Re-run stuff that we missed
|
2017-05-11 18:23:18 -04:00
|
|
|
TopicTimer.ensure_consistency!
|
2014-05-27 22:30:43 -04:00
|
|
|
|
2014-05-28 02:54:21 -04:00
|
|
|
# Forces rebake of old posts where needed, as long as no system avatars need updating
|
2014-05-30 00:17:35 -04:00
|
|
|
unless UserAvatar.where("last_gravatar_download_attempt IS NULL").limit(1).first
|
2016-08-15 06:54:30 -04:00
|
|
|
problems = Post.rebake_old(SiteSetting.rebake_old_posts_count)
|
2014-07-17 16:22:46 -04:00
|
|
|
problems.each do |hash|
|
2015-06-12 06:02:36 -04: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 16:22:46 -04:00
|
|
|
end
|
2014-05-28 02:54:21 -04:00
|
|
|
end
|
2014-06-24 03:10:56 -04:00
|
|
|
|
2014-08-05 02:37:56 -04: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 15:47:46 -05:00
|
|
|
Discourse.handle_job_exception(hash[:ex], error_context(args, "Rebaking user id #{user_id}", user_id: user_id))
|
2014-08-05 02:37:56 -04:00
|
|
|
end
|
2015-09-06 21:57:50 -04:00
|
|
|
|
2015-10-01 03:17:15 -04:00
|
|
|
offset = (SiteSetting.max_new_topics).to_i
|
2015-09-06 21:57:50 -04: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
|
|
|
|
|
|
|
|
nil
|
2013-03-28 13:02:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|