Browse Source

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

/admin/instances?availability=failing remains wholly unefficient
closed-social-glitch-2
Claire 2 years ago
committed by GitHub
parent
commit
68d1df8bc3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions
  1. +1
    -1
      app/controllers/admin/instances_controller.rb
  2. +7
    -2
      app/lib/delivery_failure_tracker.rb

+ 1
- 1
app/controllers/admin/instances_controller.rb View File

@ -57,7 +57,7 @@ module Admin
end
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|
instance.failure_days = warning_domains_map[instance.domain]

+ 7
- 2
app/lib/delivery_failure_tracker.rb View File

@ -65,8 +65,13 @@ class DeliveryFailureTracker
domains - UnavailableDomain.all.pluck(:domain)
end
def warning_domains_map
warning_domains.index_with { |domain| redis.scard(exhausted_deliveries_key_by(domain)) }
def warning_domains_map(domains = nil)
if domains.nil?
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
private

Loading…
Cancel
Save