]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-playlist-element.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video-playlist-element.ts
index e20e32f8b4bca3964195f887e1d9b7243010d316..4e41608186265c2339f89e40b3ebe25b9e07a0ce 100644 (file)
@@ -23,6 +23,7 @@ import {
   MVideoPlaylistElementVideoUrlPlaylistPrivacy,
   MVideoPlaylistVideoThumbnail
 } from '@server/types/models/video/video-playlist-element'
+import { AttributesOnly } from '@shared/typescript-utils'
 import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
 import { VideoPrivacy } from '../../../shared/models/videos'
 import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model'
@@ -32,7 +33,6 @@ import { AccountModel } from '../account/account'
 import { getSort, throwIfNotValid } from '../utils'
 import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video'
 import { VideoPlaylistModel } from './video-playlist'
-import { AttributesOnly } from '@shared/typescript-utils'
 
 @Table({
   tableName: 'videoPlaylistElement',
@@ -208,22 +208,28 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide
   }
 
   static listUrlsOfForAP (videoPlaylistId: number, start: number, count: number, t?: Transaction) {
-    const query = {
-      attributes: [ 'url' ],
-      offset: start,
-      limit: count,
-      order: getSort('position'),
-      where: {
-        videoPlaylistId
-      },
-      transaction: t
+    const getQuery = (forCount: boolean) => {
+      return {
+        attributes: forCount
+          ? []
+          : [ 'url' ],
+        offset: start,
+        limit: count,
+        order: getSort('position'),
+        where: {
+          videoPlaylistId
+        },
+        transaction: t
+      }
     }
 
-    return VideoPlaylistElementModel
-      .findAndCountAll(query)
-      .then(({ rows, count }) => {
-        return { total: count, data: rows.map(e => e.url) }
-      })
+    return Promise.all([
+      VideoPlaylistElementModel.count(getQuery(true)),
+      VideoPlaylistElementModel.findAll(getQuery(false))
+    ]).then(([ total, rows ]) => ({
+      total,
+      data: rows.map(e => e.url)
+    }))
   }
 
   static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Promise<MVideoPlaylistVideoThumbnail> {