diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-20 10:13:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-20 11:45:59 +0200 |
commit | 91411dba928678c15a5e99d9795ae061909e397d (patch) | |
tree | 7ba6e340cc9eb6f993051fcac74eefd652cb0ffd /server/controllers/api/users/me.ts | |
parent | fcc7c060374c3a547257d96af847352c14d6144b (diff) | |
download | PeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.gz PeerTube-91411dba928678c15a5e99d9795ae061909e397d.tar.zst PeerTube-91411dba928678c15a5e99d9795ae061909e397d.zip |
Limit associations fetch when loading token
Diffstat (limited to 'server/controllers/api/users/me.ts')
-rw-r--r-- | server/controllers/api/users/me.ts | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index d4b7e3715..eba1e7edd 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -38,6 +38,7 @@ import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | |||
38 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 38 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
39 | import { JobQueue } from '../../../lib/job-queue' | 39 | import { JobQueue } from '../../../lib/job-queue' |
40 | import { logger } from '../../../helpers/logger' | 40 | import { logger } from '../../../helpers/logger' |
41 | import { AccountModel } from '../../../models/account/account' | ||
41 | 42 | ||
42 | const auditLogger = auditLoggerFactory('users-me') | 43 | const auditLogger = auditLoggerFactory('users-me') |
43 | 44 | ||
@@ -329,19 +330,17 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
329 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo | 330 | if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo |
330 | 331 | ||
331 | await sequelizeTypescript.transaction(async t => { | 332 | await sequelizeTypescript.transaction(async t => { |
333 | const userAccount = await AccountModel.load(user.Account.id) | ||
334 | |||
332 | await user.save({ transaction: t }) | 335 | await user.save({ transaction: t }) |
333 | 336 | ||
334 | if (body.displayName !== undefined) user.Account.name = body.displayName | 337 | if (body.displayName !== undefined) userAccount.name = body.displayName |
335 | if (body.description !== undefined) user.Account.description = body.description | 338 | if (body.description !== undefined) userAccount.description = body.description |
336 | await user.Account.save({ transaction: t }) | 339 | await userAccount.save({ transaction: t }) |
337 | 340 | ||
338 | await sendUpdateActor(user.Account, t) | 341 | await sendUpdateActor(userAccount, t) |
339 | 342 | ||
340 | auditLogger.update( | 343 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
341 | getAuditIdFromRes(res), | ||
342 | new UserAuditView(user.toFormattedJSON()), | ||
343 | oldUserAuditView | ||
344 | ) | ||
345 | }) | 344 | }) |
346 | 345 | ||
347 | return res.sendStatus(204) | 346 | return res.sendStatus(204) |
@@ -351,15 +350,12 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
351 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] | 350 | const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] |
352 | const user: UserModel = res.locals.oauth.token.user | 351 | const user: UserModel = res.locals.oauth.token.user |
353 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) | 352 | const oldUserAuditView = new UserAuditView(user.toFormattedJSON()) |
354 | const account = user.Account | ||
355 | 353 | ||
356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account) | 354 | const userAccount = await AccountModel.load(user.Account.id) |
357 | 355 | ||
358 | auditLogger.update( | 356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount.Actor, userAccount) |
359 | getAuditIdFromRes(res), | 357 | |
360 | new UserAuditView(user.toFormattedJSON()), | 358 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
361 | oldUserAuditView | ||
362 | ) | ||
363 | 359 | ||
364 | return res.json({ avatar: avatar.toFormattedJSON() }) | 360 | return res.json({ avatar: avatar.toFormattedJSON() }) |
365 | } | 361 | } |