diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-03-26 16:02:54 +0100 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-03-26 16:02:54 +0100 |
commit | b9f314bba754074c7ac7dad37cdd35a0cbf1d1b5 (patch) | |
tree | 987f8ceff468686d7f4185cf2312e56aed45ecd1 /app/models | |
parent | 648cf8bfd51913929b7d0d3a637de496d6e40f89 (diff) | |
parent | 0c1a05b281c2665b52a644d51b9b06c2756479a7 (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - config/locales/es.yml - config/locales/pl.yml - config/locales/pt-BR.yml
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 2 | ||||
-rw-r--r-- | app/models/follow_request.rb | 2 | ||||
-rw-r--r-- | app/models/instance.rb | 6 |
3 files changed, 7 insertions, 3 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 6b539f004..a82251d2e 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -98,7 +98,7 @@ class Account < ApplicationRecord scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) } scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } scope :searchable, -> { without_suspended.where(moved_to_account_id: nil) } - scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat).where(AccountStat.arel_table[:followers_count].gteq(MIN_FOLLOWERS_DISCOVERY)).by_recent_status } + scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat).where(AccountStat.arel_table[:followers_count].gteq(MIN_FOLLOWERS_DISCOVERY)) } scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) } scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc')) } scope :popular, -> { order('account_stats.followers_count desc') } diff --git a/app/models/follow_request.rb b/app/models/follow_request.rb index c5451a050..96ac7eaa5 100644 --- a/app/models/follow_request.rb +++ b/app/models/follow_request.rb @@ -26,7 +26,7 @@ class FollowRequest < ApplicationRecord def authorize! account.follow!(target_account, reblogs: show_reblogs, uri: uri) - MergeWorker.perform_async(target_account.id, account.id) + MergeWorker.perform_async(target_account.id, account.id) if account.local? destroy! end diff --git a/app/models/instance.rb b/app/models/instance.rb index 7448d465c..7bf000d40 100644 --- a/app/models/instance.rb +++ b/app/models/instance.rb @@ -7,7 +7,7 @@ class Instance def initialize(resource) @domain = resource.domain - @accounts_count = resource.accounts_count + @accounts_count = resource.is_a?(DomainBlock) ? nil : resource.accounts_count @domain_block = resource.is_a?(DomainBlock) ? resource : DomainBlock.find_by(domain: domain) end @@ -15,6 +15,10 @@ class Instance Rails.cache.fetch("#{cache_key}/sample_accounts", expires_in: 12.hours) { Account.where(domain: domain).searchable.joins(:account_stat).popular.limit(3) } end + def cached_accounts_count + @accounts_count || Rails.cache.fetch("#{cache_key}/count", expires_in: 12.hours) { Account.where(domain: domain).count } + end + def to_param domain end |