mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-09 00:00:12 +09:00
Count unread rooms for push badges once per batch
Each push notification carries the subscriber's unread room count as its badge. The pool built it per subscription, loading the user and counting their unread memberships: two queries for every subscriber, all in the job before the deliveries reach the threads. With 1,000 subscribed members the job spent ~180 ms and 2,000 queries there; with 5,000, a second. The pool now counts the unread rooms of a whole batch with one grouped query and hands each subscription its badge; nothing else in the notification needs the user. The queries still run before the work is posted to the threads, which run outside the Rails executor. Push::Subscription#notification still counts by itself when no badge is given, as for the test notification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0142qgjggdJ2KDdGk7RF9Xm9
This commit is contained in:
@@ -125,6 +125,15 @@ class Push::SubscriptionTest < ActiveSupport::TestCase
|
||||
subscription.notification(title: "t", body: "b", path: "/").deliver
|
||||
end
|
||||
|
||||
test "the badge defaults to the subscriber's unread room count" do
|
||||
memberships(:david_pets).update! unread_at: Time.current
|
||||
memberships(:david_hq).update! unread_at: Time.current
|
||||
subscription = build_subscription(endpoint: "https://fcm.googleapis.com/fcm/send/abc123")
|
||||
|
||||
WebPush.expects(:payload_send).with { |options| JSON.parse(options[:message]).dig("options", "data", "badge") == 2 }
|
||||
subscription.notification(title: "t", body: "b", path: "/").deliver
|
||||
end
|
||||
|
||||
test "delivery sends with the pinned endpoint_ip" do
|
||||
subscription = build_subscription(endpoint: "https://fcm.googleapis.com/fcm/send/abc123")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user