mirror of
https://github.com/mastodon/mastodon.git
synced 2025-07-15 08:48:15 +00:00
Add Status#only_reblogs
scope for annual report classes (#35141)
This commit is contained in:
parent
16057f550d
commit
36f01af6c4
|
@ -32,7 +32,7 @@ class AnnualReport::Archetype < AnnualReport::Source
|
||||||
end
|
end
|
||||||
|
|
||||||
def reblogs_count
|
def reblogs_count
|
||||||
@reblogs_count ||= report_statuses.where.not(reblog_of_id: nil).count
|
@reblogs_count ||= report_statuses.only_reblogs.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies_count
|
def replies_count
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AnnualReport::MostRebloggedAccounts < AnnualReport::Source
|
||||||
private
|
private
|
||||||
|
|
||||||
def most_reblogged_accounts
|
def most_reblogged_accounts
|
||||||
report_statuses.where.not(reblog_of_id: nil).joins(reblog: :account).group(accounts: [:id]).having(minimum_reblog_count).order(count_all: :desc).limit(SET_SIZE).count
|
report_statuses.only_reblogs.joins(reblog: :account).group(accounts: [:id]).having(minimum_reblog_count).order(count_all: :desc).limit(SET_SIZE).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def minimum_reblog_count
|
def minimum_reblog_count
|
||||||
|
|
|
@ -5,7 +5,7 @@ class AnnualReport::TypeDistribution < AnnualReport::Source
|
||||||
{
|
{
|
||||||
type_distribution: {
|
type_distribution: {
|
||||||
total: report_statuses.count,
|
total: report_statuses.count,
|
||||||
reblogs: report_statuses.where.not(reblog_of_id: nil).count,
|
reblogs: report_statuses.only_reblogs.count,
|
||||||
replies: report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
|
replies: report_statuses.where.not(in_reply_to_id: nil).where.not(in_reply_to_account_id: @account.id).count,
|
||||||
standalone: report_statuses.without_replies.without_reblogs.count,
|
standalone: report_statuses.without_replies.without_reblogs.count,
|
||||||
},
|
},
|
||||||
|
|
|
@ -120,6 +120,7 @@ class Status < ApplicationRecord
|
||||||
scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
|
scope :with_accounts, ->(ids) { where(id: ids).includes(:account) }
|
||||||
scope :without_replies, -> { not_reply.or(reply_to_account) }
|
scope :without_replies, -> { not_reply.or(reply_to_account) }
|
||||||
scope :not_reply, -> { where(reply: false) }
|
scope :not_reply, -> { where(reply: false) }
|
||||||
|
scope :only_reblogs, -> { where.not(reblog_of_id: nil) }
|
||||||
scope :reply_to_account, -> { where(arel_table[:in_reply_to_account_id].eq arel_table[:account_id]) }
|
scope :reply_to_account, -> { where(arel_table[:in_reply_to_account_id].eq arel_table[:account_id]) }
|
||||||
scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) }
|
scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) }
|
||||||
scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) }
|
scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) }
|
||||||
|
|
|
@ -352,6 +352,17 @@ RSpec.describe Status do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.only_reblogs' do
|
||||||
|
let!(:status) { Fabricate :status }
|
||||||
|
let!(:reblog) { Fabricate :status, reblog: Fabricate(:status) }
|
||||||
|
|
||||||
|
it 'returns the expected statuses' do
|
||||||
|
expect(described_class.only_reblogs)
|
||||||
|
.to include(reblog)
|
||||||
|
.and not_include(status)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.tagged_with' do
|
describe '.tagged_with' do
|
||||||
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
let(:tag_cats) { Fabricate(:tag, name: 'cats') }
|
||||||
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
let(:tag_dogs) { Fabricate(:tag, name: 'dogs') }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user