mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-29 00:44:05 +09:00
Look the endpoint up past the query cache, and keep a subscription a race refused
The lookup under the write lock repeated the one made before
validation, so the query cache could answer it with that earlier miss
even after another connection had registered the endpoint. It runs
uncached now.
Enabling notifications unsubscribed the browser on any refusal, so a
session signed out between authenticating and saving lost the browser's
subscription too, and the next session had nothing to post. Only a
refused endpoint unsubscribes it now.
From #371.
(cherry picked from commit aa93269ceb)
This commit is contained in:
1 parent
fadf6f1859
commit
bf2b9cc61b
3 files changed
+42
-9
No files matched your search
@@ -28,15 +28,17 @@ class Users::PushSubscriptionsController < ApplicationController
|
||||
|
||||
# A password change ends every session and subscription. A request that authenticated just before it mustn't
|
||||
# put one back, so the session is checked under the same write lock as the save, and the endpoint is looked up
|
||||
# again there so two tabs posting at once register it once. Validation, which resolves the endpoint's address,
|
||||
# runs before taking the lock.
|
||||
# again there, past the query cache, so two tabs posting at once register it once. Validation, which resolves
|
||||
# the endpoint's address, runs before taking the lock.
|
||||
def register_while_signed_in(subscription)
|
||||
Push::Subscription.transaction do
|
||||
if Session.exists?(Current.session.id)
|
||||
if existing = @push_subscriptions.find_by(push_subscription_params)
|
||||
existing.touch
|
||||
else
|
||||
subscription.save!(validate: false)
|
||||
Push::Subscription.uncached do
|
||||
Push::Subscription.transaction do
|
||||
if Session.exists?(Current.session.id)
|
||||
if existing = @push_subscriptions.find_by(push_subscription_params)
|
||||
existing.touch
|
||||
else
|
||||
subscription.save!(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user