aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts21
1 files changed, 12 insertions, 9 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 87ad80caf..e85c5e38e 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1750,17 +1750,25 @@ export class VideoModel extends Model<VideoModel> {
1750 ] 1750 ]
1751 } 1751 }
1752 1752
1753 const [ count, ids ] = await Promise.all([ 1753 const [ count, rows ] = await Promise.all([
1754 countVideos 1754 countVideos
1755 ? VideoModel.scope(countScope).count(countQuery) 1755 ? VideoModel.scope(countScope).count(countQuery)
1756 : Promise.resolve<number>(undefined), 1756 : Promise.resolve<number>(undefined),
1757 1757
1758 VideoModel.scope(idsScope) 1758 VideoModel.scope(idsScope)
1759 .findAll(query) 1759 .findAll(Object.assign({}, query, { raw: true }))
1760 .then(rows => rows.map(r => r.id)) 1760 .then(rows => rows.map(r => r.id))
1761 .then(ids => VideoModel.loadCompleteVideosForApi(ids, query, options))
1761 ]) 1762 ])
1762 1763
1763 if (ids.length === 0) return { data: [], total: count } 1764 return {
1765 data: rows,
1766 total: count
1767 }
1768 }
1769
1770 private static loadCompleteVideosForApi (ids: number[], query: FindOptions, options: AvailableForListIDsOptions) {
1771 if (ids.length === 0) return []
1764 1772
1765 const secondQuery: FindOptions = { 1773 const secondQuery: FindOptions = {
1766 offset: 0, 1774 offset: 0,
@@ -1789,12 +1797,7 @@ export class VideoModel extends Model<VideoModel> {
1789 ] 1797 ]
1790 }) 1798 })
1791 1799
1792 const rows = await VideoModel.scope(apiScope).findAll(secondQuery) 1800 return VideoModel.scope(apiScope).findAll(secondQuery)
1793
1794 return {
1795 data: rows,
1796 total: count
1797 }
1798 } 1801 }
1799 1802
1800 private static isPrivacyForFederation (privacy: VideoPrivacy) { 1803 private static isPrivacyForFederation (privacy: VideoPrivacy) {