mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 03:23:50 +08:00
The main functional change is that DirectoryRefresh will now run every hour on sites with less than 100 users (configurable). This is to ensure activity is up to date more quickly on the directory for new sites. This also consolidates the two jobs into one, easier to reason about.
33 lines
896 B
Ruby
Vendored
33 lines
896 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class DirectoryRefresh < ::Jobs::Scheduled
|
|
every 1.hour
|
|
|
|
OLDER_PERIODS_REFRESH_KEY = "directory_older_periods_last_refresh"
|
|
|
|
def execute(args)
|
|
DirectoryItem.refresh_period!(:daily)
|
|
|
|
older_periods = DirectoryItem.period_types.keys - [:daily]
|
|
|
|
# on smaller site, update hourly, otherwise update daily
|
|
if small_site? || older_periods_due?
|
|
older_periods.each { |p| DirectoryItem.refresh_period!(p) }
|
|
Discourse.redis.set(OLDER_PERIODS_REFRESH_KEY, Time.zone.now.to_i)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def small_site?
|
|
limit = SiteSetting.directory_hourly_refresh_max_users
|
|
limit > 0 && User.human_users.count <= limit
|
|
end
|
|
|
|
def older_periods_due?
|
|
last = Discourse.redis.get(OLDER_PERIODS_REFRESH_KEY)
|
|
last.nil? || Time.zone.at(last.to_i) < 23.hours.ago
|
|
end
|
|
end
|
|
end
|