diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:06:13 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:17:36 +0200 |
commit | 14d3270f363245d2c83fcc2ac109e39743b5627e (patch) | |
tree | 22a1d40675d372d53c35a4d7adf1fc1b4ceb1799 /server/models/user/user.ts | |
parent | aa8b6df4a51c82eb91e6fd71a090b2128098af6b (diff) | |
download | PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.gz PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.zst PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.zip |
Change how we handle resolution
It was an enum before, now we just use video height
Diffstat (limited to 'server/models/user/user.ts')
-rw-r--r-- | server/models/user/user.ts | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 7a21dbefa..0dc52d3cf 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts | |||
@@ -12,7 +12,6 @@ import { | |||
12 | isUserDisplayNSFWValid, | 12 | isUserDisplayNSFWValid, |
13 | isUserVideoQuotaValid | 13 | isUserVideoQuotaValid |
14 | } from '../../helpers' | 14 | } from '../../helpers' |
15 | import { VideoResolution } from '../../../shared' | ||
16 | 15 | ||
17 | import { addMethodsToModel } from '../utils' | 16 | import { addMethodsToModel } from '../utils' |
18 | import { | 17 | import { |
@@ -243,33 +242,21 @@ loadByUsernameOrEmail = function (username: string, email: string) { | |||
243 | // --------------------------------------------------------------------------- | 242 | // --------------------------------------------------------------------------- |
244 | 243 | ||
245 | function getOriginalVideoFileTotalFromUser (user: UserInstance) { | 244 | function getOriginalVideoFileTotalFromUser (user: UserInstance) { |
246 | // attributes = [] because we don't want other fields than the sum | 245 | // Don't use sequelize because we need to use a subquery |
247 | const query = { | 246 | const query = 'SELECT SUM("size") AS "total" FROM ' + |
248 | where: { | 247 | '(SELECT MAX("VideoFiles"."size") AS "size" FROM "VideoFiles" ' + |
249 | resolution: VideoResolution.ORIGINAL | 248 | 'INNER JOIN "Videos" ON "VideoFiles"."videoId" = "Videos"."id" ' + |
250 | }, | 249 | 'INNER JOIN "Authors" ON "Videos"."authorId" = "Authors"."id" ' + |
251 | include: [ | 250 | 'INNER JOIN "Users" ON "Authors"."userId" = "Users"."id" ' + |
252 | { | 251 | 'WHERE "Users"."id" = $userId GROUP BY "Videos"."id") t' |
253 | attributes: [], | 252 | |
254 | model: User['sequelize'].models.Video, | 253 | const options = { |
255 | include: [ | 254 | bind: { userId: user.id }, |
256 | { | 255 | type: Sequelize.QueryTypes.SELECT |
257 | attributes: [], | ||
258 | model: User['sequelize'].models.Author, | ||
259 | include: [ | ||
260 | { | ||
261 | attributes: [], | ||
262 | model: User['sequelize'].models.User, | ||
263 | where: { | ||
264 | id: user.id | ||
265 | } | ||
266 | } | ||
267 | ] | ||
268 | } | ||
269 | ] | ||
270 | } | ||
271 | ] | ||
272 | } | 256 | } |
257 | return User['sequelize'].query(query, options).then(([ { total } ]) => { | ||
258 | if (total === null) return 0 | ||
273 | 259 | ||
274 | return User['sequelize'].models.VideoFile.sum('size', query) | 260 | return parseInt(total, 10) |
261 | }) | ||
275 | } | 262 | } |