Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/models/account.rb`: Not a real conflict, just upstream getting rid of unused constants too close to glitch-soc-specific contents. Removed unused constants like upstream did. - `app/models/trends.rb`: Conflict because glitch-soc disabled email notifications for trending links. Upstream has refactored this quite a bit and added trending posts. Took upstream code, but disabling the extra trending stuff will come in another commit. - `app/views/admin/trends/links/index.html.haml`: Conflict due to glitch-soc's theming system. Ported upstream changes accordingly.
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::EmailDomainBlockRefreshScheduler
|
||||
include Sidekiq::Worker
|
||||
include Redisable
|
||||
|
||||
sidekiq_options retry: 0
|
||||
|
||||
def perform
|
||||
Resolv::DNS.open do |dns|
|
||||
dns.timeouts = 5
|
||||
|
||||
EmailDomainBlock.find_each do |email_domain_block|
|
||||
ips = begin
|
||||
if ip?(email_domain_block.domain)
|
||||
[email_domain_block.domain]
|
||||
else
|
||||
dns.getresources(email_domain_block.domain, Resolv::DNS::Resource::IN::A).to_a + dns.getresources(email_domain_block.domain, Resolv::DNS::Resource::IN::AAAA).to_a.map { |resource| resource.address.to_s }
|
||||
end
|
||||
end
|
||||
|
||||
email_domain_block.update(ips: ips, last_refresh_at: Time.now.utc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def ip?(str)
|
||||
str =~ Regexp.union([Resolv::IPv4::Regex, Resolv::IPv6::Regex])
|
||||
end
|
||||
end
|
@ -18,7 +18,7 @@ class Scheduler::FollowRecommendationsScheduler
|
||||
|
||||
fallback_recommendations = FollowRecommendation.order(rank: :desc).limit(SET_SIZE)
|
||||
|
||||
I18n.available_locales.map { |locale| locale.to_s.split(/[_-]/).first }.uniq.each do |locale|
|
||||
Trends.available_locales.each do |locale|
|
||||
recommendations = begin
|
||||
if AccountSummary.safe.filtered.localized(locale).exists? # We can skip the work if no accounts with that language exist
|
||||
FollowRecommendation.localized(locale).order(rank: :desc).limit(SET_SIZE).map { |recommendation| [recommendation.account_id, recommendation.rank] }
|
||||
@ -49,11 +49,11 @@ class Scheduler::FollowRecommendationsScheduler
|
||||
end
|
||||
end
|
||||
|
||||
redis.pipelined do
|
||||
redis.del(key(locale))
|
||||
redis.multi do |multi|
|
||||
multi.del(key(locale))
|
||||
|
||||
recommendations.each do |(account_id, rank)|
|
||||
redis.zadd(key(locale), rank, account_id)
|
||||
multi.zadd(key(locale), rank, account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user