0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 09:44:06 +08:00
discourse/app/jobs/scheduled/periodical_updates.rb
David Taylor 37b64504c9
FEATURE: Support markdown in tag descriptions (#41996)
We previously supported a subset of HTML in tag descriptions, but the
escaping/unescaping of characters wasn't perfectly consistent, so
results could be surprising.

This commit runs tag descriptions through our standard markdown
pipeline, which supports the same subset of HTML, plus real markdown. It
also adds the standard DEditor in tag editing forms. This has parity
with group/user bios, and with category descriptions.

Now the character support is clearly defined, and perfectly matches
other parts of Discourse.

---

<img width="527" height="545" alt="SCR-20260723-rdpm"
src="https://github.com/user-attachments/assets/812a9a3a-ece7-4594-8d9b-65e7e30649c8"
/>

---

<img width="564" height="213" alt="SCR-20260723-rduy"
src="https://github.com/user-attachments/assets/4ea4a6ff-81d3-4489-95b3-bf5f9b1e5fa0"
/>
---
2026-07-29 14:43:47 +01:00

74 lines
2.4 KiB
Ruby
Vendored

# frozen_string_literal: true
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.
class PeriodicalUpdates < ::Jobs::Scheduled
every 15.minutes
def self.should_update_long_topics?
@call_count ||= 0
@call_count += 1
# once every 6 hours
(@call_count % 24) == 1
end
def execute(_ = nil)
# Feature topics in categories
CategoryFeaturedTopic.feature_topics(batched: true)
# Update the scores of posts
args = { min_topic_age: 1.day.ago }
args[:max_topic_length] = 500 unless self.class.should_update_long_topics?
ScoreCalculator.new.calculate(args)
# Forces rebake of old posts where needed, as long as no system avatars need updating
if !SiteSetting.automatically_download_gravatars ||
!UserAvatar
.joins(user: :user_emails)
.where(user_emails: { primary: true }, last_gravatar_download_attempt: nil)
.exists?
problems = Post.rebake_old(SiteSetting.rebake_old_posts_count, priority: :ultra_low)
problems.each do |hash|
post_id = hash[:post].id
Discourse.handle_job_exception(
hash[:ex],
error_context(args, "Rebaking post id #{post_id}", post_id: post_id),
)
end
end
# rebake out of date user profiles
problems = UserProfile.rebake_old(250)
problems.each do |hash|
user_id = hash[:profile].user_id
Discourse.handle_job_exception(
hash[:ex],
error_context(args, "Rebaking user id #{user_id}", user_id: user_id),
)
end
# rebake out of date tag descriptions
[Tag, TagLocalization].each do |klass|
klass
.rebake_old(250)
.each do |hash|
record = hash[:record]
Discourse.handle_job_exception(
hash[:ex],
error_context(args, "Rebaking #{klass.name} id #{record.id}", record_id: record.id),
)
end
end
offset = SiteSetting.max_new_topics.to_i
last_new_topic = Topic.order("created_at desc").offset(offset).select(:created_at).first
SiteSetting.min_new_topics_time = last_new_topic.created_at.to_i if last_new_topic
Category.auto_bump_topic!
nil
end
end
end