pattern = 'google\.[a-z.]+/share\.google\?'
scope = :local # :local or :remote (anything else for both).
since = 90.days.ago # set to nil to search all time (slow on a big instance)
statuses = Status.unscoped
.joins(:account)
.where(deleted_at: nil)
.where('statuses.text ~* ?', pattern)
statuses = statuses.where('statuses.created_at > ?', since) if since
statuses = statuses.where(accounts: { domain: nil }) if scope == :local
statuses = statuses.where.not(accounts: { domain: nil }) if scope == :remote
counts = statuses.group('statuses.account_id').count
accounts = Account.where(id: counts.keys).index_by(&:id)
counts.sort_by { |_, n| -n }.each do |id, n|
puts "@#{accounts[id].acct} (#{n})"
end
nil
results in a nice list

Categories: Uncategorised
Leave a Reply