Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

More robust user deletion

Chocobozzz0ec8b1cb3e9d
diff --git a/server/core/controllers/api/users/index.ts b/server/core/controllers/api/users/index.ts
index c0bfad58c7..395f37a0cb 100644
--- a/server/core/controllers/api/users/index.ts
+++ b/server/core/controllers/api/users/index.ts
@@ -48,6 +48,7 @@ import { registrationsRouter } from './registrations.js'
import { twoFactorRouter } from './two-factor.js'
import { userExportsRouter } from './user-exports.js'
import { userImportRouter } from './user-imports.js'
+import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const auditLogger = auditLoggerFactory('users')
const lTags = loggerTagsFactory('api', 'users')
@@ -241,9 +242,11 @@ async function removeUser (req: express.Request, res: express.Response) {
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
- await sequelizeTypescript.transaction(async t => {
- // Use a transaction to avoid inconsistencies with hooks (account/channel deletion & federation)
- await user.destroy({ transaction: t })
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(t => {
+ // Use a transaction to avoid inconsistencies with hooks (account/channel deletion & federation)
+ return user.destroy({ transaction: t })
+ })
})
logger.info(`Removed user ${user.username} by moderator ${byUser.username}.`, lTags(user.username, byUser.username))
diff --git a/server/core/controllers/api/users/me.ts b/server/core/controllers/api/users/me.ts
index 349259b3c2..ebefad6ff1 100644
--- a/server/core/controllers/api/users/me.ts
+++ b/server/core/controllers/api/users/me.ts
@@ -49,6 +49,7 @@ import { AccountModel } from '../../../models/account/account.js'
import { UserModel } from '../../../models/user/user.js'
import { VideoImportModel } from '../../../models/video/video-import.js'
import { VideoModel } from '../../../models/video/video.js'
+import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
const auditLogger = auditLoggerFactory('users')
@@ -262,7 +263,11 @@ async function deleteMe (req: express.Request, res: express.Response) {
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
- await user.destroy()
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(t => {
+ return user.destroy({ transaction: t })
+ })
+ })
Hooks.runAction('action:api.user.deleted', { user, req, res })