Fix some performance issues with /admin/instances (#21907) (#23483)

/admin/instances?availability=failing remains wholly unefficient
This commit is contained in:
Claire 2023-02-09 20:57:14 +01:00 committed by GitHub
parent 0ca877f084
commit 1f0be21317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -57,7 +57,7 @@ module Admin
end end
def preload_delivery_failures! def preload_delivery_failures!
warning_domains_map = DeliveryFailureTracker.warning_domains_map warning_domains_map = DeliveryFailureTracker.warning_domains_map(@instances.map(&:domain))
@instances.each do |instance| @instances.each do |instance|
instance.failure_days = warning_domains_map[instance.domain] instance.failure_days = warning_domains_map[instance.domain]

View file

@ -65,8 +65,13 @@ class DeliveryFailureTracker
domains - UnavailableDomain.all.pluck(:domain) domains - UnavailableDomain.all.pluck(:domain)
end end
def warning_domains_map def warning_domains_map(domains = nil)
if domains.nil?
warning_domains.index_with { |domain| redis.scard(exhausted_deliveries_key_by(domain)) } warning_domains.index_with { |domain| redis.scard(exhausted_deliveries_key_by(domain)) }
else
domains -= UnavailableDomain.where(domain: domains).pluck(:domain)
domains.index_with { |domain| redis.scard(exhausted_deliveries_key_by(domain)) }.filter { |_, days| days.positive? }
end
end end
private private