Extract counters from accounts table to account_stats table (#9295)

This commit is contained in:
Eugen Rochko
2018-11-19 00:43:52 +01:00
committed by GitHub
parent 4fdefffb99
commit d6b9a62e0a
25 changed files with 203 additions and 68 deletions

View File

@ -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