From e2d803800d712fc3b2db0edd5668d03ed30f9ffe Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Mon, 9 Sep 2024 13:27:21 -0400 Subject: [PATCH] fix: removes transactions wrapping auth strategies and login (#8137) ## Description By default all api requests are creating transactions due to the authentication stategy. This change removes transactions for auth and login requests. This should only happen when the database needs to make changes in which case the auth strategy or login lockout updates will invoke their own transactions still. This should improve performance without any sacrifice to database consistency. Fixes #8092 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [ ] Chore (non-breaking change which does not add functionality) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Change to the [templates](https://github.com/payloadcms/payload/tree/main/templates) directory (does not affect core functionality) - [ ] Change to the [examples](https://github.com/payloadcms/payload/tree/main/examples) directory (does not affect core functionality) - [ ] This change requires a documentation update ## Checklist: - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] Existing test suite passes locally with my changes - [ ] I have made corresponding changes to the documentation --- packages/payload/src/auth/operations/auth.ts | 8 -------- packages/payload/src/auth/operations/login.ts | 12 ------------ 2 files changed, 20 deletions(-) diff --git a/packages/payload/src/auth/operations/auth.ts b/packages/payload/src/auth/operations/auth.ts index efb2f1d568..110abaab50 100644 --- a/packages/payload/src/auth/operations/auth.ts +++ b/packages/payload/src/auth/operations/auth.ts @@ -2,8 +2,6 @@ import type { TypedUser } from '../../index.js' import type { PayloadRequest } from '../../types/index.js' import type { Permissions } from '../types.js' -import { commitTransaction } from '../../utilities/commitTransaction.js' -import { initTransaction } from '../../utilities/initTransaction.js' import { killTransaction } from '../../utilities/killTransaction.js' import { executeAuthStrategies } from '../executeAuthStrategies.js' import { getAccessResults } from '../getAccessResults.js' @@ -25,8 +23,6 @@ export const auth = async (args: Required): Promise => { const { payload } = req try { - const shouldCommit = await initTransaction(req) - const { responseHeaders, user } = await executeAuthStrategies({ headers, payload, @@ -39,10 +35,6 @@ export const auth = async (args: Required): Promise => { req, }) - if (shouldCommit) { - await commitTransaction(req) - } - return { permissions, responseHeaders, diff --git a/packages/payload/src/auth/operations/login.ts b/packages/payload/src/auth/operations/login.ts index d3d0375496..cc4535a848 100644 --- a/packages/payload/src/auth/operations/login.ts +++ b/packages/payload/src/auth/operations/login.ts @@ -12,8 +12,6 @@ import type { User } from '../types.js' import { buildAfterOperation } from '../../collections/operations/utils.js' import { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js' import { afterRead } from '../../fields/hooks/afterRead/index.js' -import { commitTransaction } from '../../utilities/commitTransaction.js' -import { initTransaction } from '../../utilities/initTransaction.js' import { killTransaction } from '../../utilities/killTransaction.js' import sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js' import { getFieldsToSign } from '../getFieldsToSign.js' @@ -43,8 +41,6 @@ export const loginOperation = async ( let args = incomingArgs try { - const shouldCommit = await initTransaction(args.req) - // ///////////////////////////////////// // beforeOperation - Collection // ///////////////////////////////////// @@ -202,10 +198,6 @@ export const loginOperation = async ( }) } - if (shouldCommit) { - await commitTransaction(req) - } - throw new AuthenticationError(req.t) } @@ -334,10 +326,6 @@ export const loginOperation = async ( // Return results // ///////////////////////////////////// - if (shouldCommit) { - await commitTransaction(req) - } - return result } catch (error: unknown) { await killTransaction(args.req)