You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

  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 user_count
  17. Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
  18. end
  19. def active_user_count
  20. Rails.cache.fetch('active_user_count') { Redis.current.pfcount(*(0..3).map { |i| "activity:logins:#{i.weeks.ago.utc.to_date.cweek}" }) }
  21. end
  22. def status_count
  23. Rails.cache.fetch('local_status_count') { Account.local.joins(:account_stat).sum('account_stats.statuses_count') }.to_i
  24. end
  25. def domain_count
  26. Rails.cache.fetch('distinct_domain_count') { Account.distinct.count(:domain) }
  27. end
  28. def sample_accounts
  29. Rails.cache.fetch('sample_accounts', expires_in: 12.hours) { Account.discoverable.popular.limit(3) }
  30. end
  31. def version_number
  32. Mastodon::Version
  33. end
  34. def commit_hash
  35. current_release_file = Pathname.new('CURRENT_RELEASE').expand_path
  36. if current_release_file.file?
  37. IO.read(current_release_file).strip!
  38. else
  39. ''
  40. end
  41. end
  42. def source_url
  43. Mastodon::Version.source_url
  44. end
  45. def thumbnail
  46. @thumbnail ||= Rails.cache.fetch('site_uploads/thumbnail') { SiteUpload.find_by(var: 'thumbnail') }
  47. end
  48. def hero
  49. @hero ||= Rails.cache.fetch('site_uploads/hero') { SiteUpload.find_by(var: 'hero') }
  50. end
  51. def mascot
  52. @mascot ||= Rails.cache.fetch('site_uploads/mascot') { SiteUpload.find_by(var: 'mascot') }
  53. end
  54. end