diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-11-19 00:43:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-19 00:43:52 +0100 |
commit | d6b9a62e0a13497b8cc40eb1db56d1ec2b3760ea (patch) | |
tree | f8627888dd9dce43f66427261a90a3e9886b4df7 /app/models/account.rb | |
parent | 4fdefffb9906ffc3e5fde7af652674bebffd6e15 (diff) |
Extract counters from accounts table to account_stats table (#9295)
Diffstat (limited to 'app/models/account.rb')
-rw-r--r-- | app/models/account.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 44963f3e6..593ee29f7 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -32,9 +32,6 @@ # suspended :boolean default(FALSE), not null # locked :boolean default(FALSE), not null # header_remote_url :string default(""), not null -# statuses_count :integer default(0), not null -# followers_count :integer default(0), not null -# following_count :integer default(0), not null # last_webfingered_at :datetime # inbox_url :string default(""), not null # outbox_url :string default(""), not null @@ -58,6 +55,7 @@ class Account < ApplicationRecord include AccountInteractions include Attachmentable include Paginable + include AccountCounters enum protocol: [:ostatus, :activitypub] @@ -119,8 +117,6 @@ class Account < ApplicationRecord scope :remote, -> { where.not(domain: nil) } scope :local, -> { where(domain: nil) } - scope :without_followers, -> { where(followers_count: 0) } - scope :with_followers, -> { where('followers_count > 0') } scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) } scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) } scope :silenced, -> { where(silenced: true) } @@ -385,7 +381,9 @@ class Account < ApplicationRecord LIMIT ? SQL - find_by_sql([sql, limit]) + records = find_by_sql([sql, limit]) + ActiveRecord::Associations::Preloader.new.preload(records, :account_stat) + records end def advanced_search_for(terms, account, limit = 10, following = false) @@ -412,7 +410,7 @@ class Account < ApplicationRecord LIMIT ? SQL - find_by_sql([sql, account.id, account.id, account.id, limit]) + records = find_by_sql([sql, account.id, account.id, account.id, limit]) else sql = <<-SQL.squish SELECT @@ -428,8 +426,11 @@ class Account < ApplicationRecord LIMIT ? SQL - find_by_sql([sql, account.id, account.id, limit]) + records = find_by_sql([sql, account.id, account.id, limit]) end + + ActiveRecord::Associations::Preloader.new.preload(records, :account_stat) + records end private |