instance_presenter.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # frozen_string_literal: true
  2. class InstancePresenter
  3. delegate(
  4. :site_contact_email,
  5. :site_title,
  6. :site_short_description,
  7. :site_description,
  8. :site_extended_description,
  9. :site_terms,
  10. :closed_registrations_message,
  11. to: Setting
  12. )
  13. def contact_account
  14. Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
  15. end
  16. def rules
  17. Rule.ordered
  18. end
  19. def user_count
  20. Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
  21. end
  22. def active_user_count(num_weeks = 4)
  23. Rails.cache.fetch("active_user_count/#{num_weeks}") { ActivityTracker.new('activity:logins', :unique).sum(num_weeks.weeks.ago) }
  24. end
  25. def status_count
  26. Rails.cache.fetch('local_status_count') { Account.local.joins(:account_stat).sum('account_stats.statuses_count') }.to_i
  27. end
  28. def domain_count
  29. Rails.cache.fetch('distinct_domain_count') { Instance.count }
  30. end
  31. def sample_accounts
  32. Rails.cache.fetch('sample_accounts', expires_in: 12.hours) { Account.local.discoverable.popular.limit(3) }
  33. end
  34. def version_number
  35. Mastodon::Version
  36. end
  37. def source_url
  38. Mastodon::Version.source_url
  39. end
  40. def thumbnail
  41. @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') }
  42. end
  43. def hero
  44. @hero ||= Rails.cache.fetch('site_uploads/hero') { SiteUpload.find_by(var: 'hero') }
  45. end
  46. def mascot
  47. @mascot ||= Rails.cache.fetch('site_uploads/mascot') { SiteUpload.find_by(var: 'mascot') }
  48. end
  49. end