-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: speed up team upgrade #9902
Conversation
Signed-off-by: Matt Krick <matt.krick@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
With this PR, we don't need to listen to webhooks to test the card payment locally, but the org isn't upgraded to the team
tier as upgradeToTeamTier
isn't called via the webhook.
Other possible low-hanging fruit could be upgrading the Stripe API from version 2020-08-27 to 2024-06-20, but I don't see anything about relevant performance improvements in their changelog, so maybe not: https://docs.stripe.com/upgrades#api-changelog
const res = await manager.attachPaymentToCustomer(customerId, paymentMethodId) | ||
if (res instanceof Error) return standardError(res, {userId: viewerId}) | ||
// wait until the payment is attached to the customer before updating the default payment method | ||
await manager.updateDefaultPaymentMethod(customerId, paymentMethodId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the edge case where a user is upgrading for a second time, we could use a Promise.all
to speed things up a bit here? Something like:
const [attachPaymentResult, updateDefaultPaymentResult] = await Promise.all([
manager.attachPaymentToCustomer(customerId, paymentMethodId),
manager.updateDefaultPaymentMethod(customerId, paymentMethodId)
])
if (attachPaymentResult instanceof Error) return standardError(attachPaymentResult, {userId: viewerId})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried this...
nope, gotta attach first. ah well, not too bad since re-upgrade is such an edge case!
} else { | ||
customer = await manager.createCustomer(orgId, email, paymentMethodId) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we could remove the await
on line 65 when updating rethinkdb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was thinking about that! but since our DB is colocated it's usually only a couple ms so I figured probably better to be safe than sorry in case the write failed for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second look, we should completely get rid of the write to the DB here!
We should only update our DB when the payment succeeds, otherwise if we update the stripeSubscriptionId & then the 3D payment fails, the org gets stuck in a weird state where it can't upgrade because it has a subscription, but it can't downgrade because it's still on the starter tier 😬
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Description
Upgrading via stripe takes too long!
It's still too long, but this shaves off about 2 seconds (in the video it was 6!) & now you don't need to listen to webhooks to test locally.
Demo
https://www.loom.com/share/a2482e91d4b940e19dd31f66fb7fa119?sid=67a06848-bc0e-490d-85ac-3d230073d975