From 49a09a2840a8dba6f2c87de2572dce39bfb2f565 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 23 Mar 2025 11:06:13 -0400 Subject: [PATCH] Add missing locks --- server/routes/api/notifications/notifications.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/routes/api/notifications/notifications.ts b/server/routes/api/notifications/notifications.ts index e1686ce264..f3c95bb437 100644 --- a/server/routes/api/notifications/notifications.ts +++ b/server/routes/api/notifications/notifications.ts @@ -28,6 +28,7 @@ const pixel = Buffer.from( const handleUnsubscribe = async ( ctx: APIContext ) => { + const { transaction } = ctx.state; const eventType = (ctx.input.body.eventType ?? ctx.input.query.eventType) as NotificationEventType; const userId = (ctx.input.body.userId ?? ctx.input.query.userId) as string; @@ -45,6 +46,8 @@ const handleUnsubscribe = async ( const user = await User.scope("withTeam").findByPk(userId, { rejectOnEmpty: true, + lock: transaction.LOCK.UPDATE, + transaction, }); user.setNotificationEventType(eventType, false); @@ -144,7 +147,13 @@ router.get( transaction(), async (ctx: APIContext) => { const { id, token } = ctx.input.query; - const notification = await Notification.unscoped().findByPk(id); + const { transaction } = ctx.state; + + const notification = await Notification.unscoped().findByPk(id, { + lock: transaction.LOCK.UPDATE, + rejectOnEmpty: true, + transaction, + }); if (!notification || !safeEqual(token, notification.pixelToken)) { throw AuthenticationError();