Automatically remove invalid Web::PushSubscriptions (#35987)

This commit is contained in:
Emelia Smith 2025-09-04 10:00:44 +02:00 committed by GitHub
parent 14cb5ff881
commit 4c2a2c27c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -15,6 +15,15 @@ class Web::PushNotificationWorker
return if @notification.updated_at < TTL.ago
# Clean up old Web::PushSubscriptions that were added before validation of
# the endpoint and keys: #30542, #30540
unless @subscription.valid?
Rails.logger.debug { "Web::PushSubscription is invalid, removing: #{subscription_id}" }
@subscription.destroy!
return
end
# Polymorphically associated activity could have been deleted
# in the meantime, so we have to double-check before proceeding
return unless @notification.activity.present? && @subscription.pushable?(@notification)