From 68b545ef338fc772c56d0f9dde781698b5730ae6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 7 Nov 2024 05:32:33 -0500 Subject: [PATCH] Add `Status.not_direct_visibility` scope (#32065) --- app/models/account_statuses_cleanup_policy.rb | 2 +- app/models/status.rb | 1 + lib/mastodon/cli/cache.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/account_statuses_cleanup_policy.rb b/app/models/account_statuses_cleanup_policy.rb index 6e998e2dca..ef41bb3ee3 100644 --- a/app/models/account_statuses_cleanup_policy.rb +++ b/app/models/account_statuses_cleanup_policy.rb @@ -130,7 +130,7 @@ class AccountStatusesCleanupPolicy < ApplicationRecord end def without_direct_scope - Status.where.not(visibility: :direct) + Status.not_direct_visibility end def old_enough_scope(max_id = nil) diff --git a/app/models/status.rb b/app/models/status.rb index f0a4f50ff6..c58de5114c 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -127,6 +127,7 @@ class Status < ApplicationRecord } scope :distributable_visibility, -> { where(visibility: %i(public unlisted)) } scope :list_eligible_visibility, -> { where(visibility: %i(public unlisted private)) } + scope :not_direct_visibility, -> { where.not(visibility: :direct) } after_create_commit :trigger_create_webhooks after_update_commit :trigger_update_webhooks diff --git a/lib/mastodon/cli/cache.rb b/lib/mastodon/cli/cache.rb index f32ab292ee..cfb6cba1ff 100644 --- a/lib/mastodon/cli/cache.rb +++ b/lib/mastodon/cli/cache.rb @@ -52,7 +52,7 @@ module Mastodon::CLI account.account_stat.tap do |account_stat| account_stat.following_count = account.active_relationships.count account_stat.followers_count = account.passive_relationships.count - account_stat.statuses_count = account.statuses.where.not(visibility: :direct).count + account_stat.statuses_count = account.statuses.not_direct_visibility.count account_stat.save if account_stat.changed? end @@ -60,7 +60,7 @@ module Mastodon::CLI def recount_status_stats(status) status.status_stat.tap do |status_stat| - status_stat.replies_count = status.replies.where.not(visibility: :direct).count + status_stat.replies_count = status.replies.not_direct_visibility.count status_stat.reblogs_count = status.reblogs.count status_stat.favourites_count = status.favourites.count