Fix notification requests from suspended accounts still being listed (#32354)
parent
45a520603b
commit
e5e0144957
|
@ -52,7 +52,7 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_requests
|
def load_requests
|
||||||
requests = NotificationRequest.where(account: current_account).includes(:last_status, from_account: [:account_stat, :user]).to_a_paginated_by_id(
|
requests = NotificationRequest.where(account: current_account).without_suspended.includes(:last_status, from_account: [:account_stat, :user]).to_a_paginated_by_id(
|
||||||
limit_param(DEFAULT_ACCOUNTS_LIMIT),
|
limit_param(DEFAULT_ACCOUNTS_LIMIT),
|
||||||
params_slice(:max_id, :since_id, :min_id)
|
params_slice(:max_id, :since_id, :min_id)
|
||||||
)
|
)
|
||||||
|
|
|
@ -62,6 +62,6 @@ class NotificationPolicy < ApplicationRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def pending_notification_requests
|
def pending_notification_requests
|
||||||
@pending_notification_requests ||= notification_requests.limit(MAX_MEANINGFUL_COUNT).pick(Arel.sql('count(*), coalesce(sum(notifications_count), 0)::bigint'))
|
@pending_notification_requests ||= notification_requests.without_suspended.limit(MAX_MEANINGFUL_COUNT).pick(Arel.sql('count(*), coalesce(sum(notifications_count), 0)::bigint'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,8 @@ class NotificationRequest < ApplicationRecord
|
||||||
|
|
||||||
before_save :prepare_notifications_count
|
before_save :prepare_notifications_count
|
||||||
|
|
||||||
|
scope :without_suspended, -> { joins(:from_account).merge(Account.without_suspended) }
|
||||||
|
|
||||||
def self.preload_cache_collection(requests)
|
def self.preload_cache_collection(requests)
|
||||||
cached_statuses_by_id = yield(requests.filter_map(&:last_status)).index_by(&:id) # Call cache_collection in block
|
cached_statuses_by_id = yield(requests.filter_map(&:last_status)).index_by(&:id) # Call cache_collection in block
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,25 @@ RSpec.describe NotificationPolicy do
|
||||||
subject { Fabricate(:notification_policy) }
|
subject { Fabricate(:notification_policy) }
|
||||||
|
|
||||||
let(:sender) { Fabricate(:account) }
|
let(:sender) { Fabricate(:account) }
|
||||||
|
let(:suspended_sender) { Fabricate(:account) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fabricate.times(2, :notification, account: subject.account, activity: Fabricate(:status, account: sender), filtered: true, type: :mention)
|
Fabricate.times(2, :notification, account: subject.account, activity: Fabricate(:status, account: sender), filtered: true, type: :mention)
|
||||||
Fabricate(:notification_request, account: subject.account, from_account: sender)
|
Fabricate(:notification_request, account: subject.account, from_account: sender)
|
||||||
|
|
||||||
|
Fabricate(:notification, account: subject.account, activity: Fabricate(:status, account: suspended_sender), filtered: true, type: :mention)
|
||||||
|
Fabricate(:notification_request, account: subject.account, from_account: suspended_sender)
|
||||||
|
|
||||||
|
suspended_sender.suspend!
|
||||||
|
|
||||||
subject.summarize!
|
subject.summarize!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets pending_requests_count' do
|
it 'sets pending_requests_count and pending_notifications_count' do
|
||||||
expect(subject.pending_requests_count).to eq 1
|
expect(subject).to have_attributes(
|
||||||
end
|
pending_requests_count: 1,
|
||||||
|
pending_notifications_count: 2
|
||||||
it 'sets pending_notifications_count' do
|
)
|
||||||
expect(subject.pending_notifications_count).to eq 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue