aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-05 17:08:47 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-08 15:38:45 +0100
commit81b46cbc3417c46263c210c61b51a84a457abaaa (patch)
tree8ac0a8757ef22013e07d5d4632e6d79671229558 /server/models/video
parent9162476fe9fe022ff24bd42ff828aca7c68129ef (diff)
downloadPeerTube-81b46cbc3417c46263c210c61b51a84a457abaaa.tar.gz
PeerTube-81b46cbc3417c46263c210c61b51a84a457abaaa.tar.zst
PeerTube-81b46cbc3417c46263c210c61b51a84a457abaaa.zip
Optimize videos list API endpoint
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video.ts21
1 files changed, 11 insertions, 10 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 0ecb8d600..3f6fd8dc0 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1658,17 +1658,18 @@ export class VideoModel extends Model {
1658 'createdAt', 1658 'createdAt',
1659 'updatedAt' 1659 'updatedAt'
1660 ] 1660 ]
1661 const buildOpts = { raw: true }
1661 1662
1662 function buildActor (rowActor: any) { 1663 function buildActor (rowActor: any) {
1663 const avatarModel = rowActor.Avatar.id !== null 1664 const avatarModel = rowActor.Avatar.id !== null
1664 ? new AvatarModel(pick(rowActor.Avatar, avatarKeys)) 1665 ? new AvatarModel(pick(rowActor.Avatar, avatarKeys), buildOpts)
1665 : null 1666 : null
1666 1667
1667 const serverModel = rowActor.Server.id !== null 1668 const serverModel = rowActor.Server.id !== null
1668 ? new ServerModel(pick(rowActor.Server, serverKeys)) 1669 ? new ServerModel(pick(rowActor.Server, serverKeys), buildOpts)
1669 : null 1670 : null
1670 1671
1671 const actorModel = new ActorModel(pick(rowActor, actorKeys)) 1672 const actorModel = new ActorModel(pick(rowActor, actorKeys), buildOpts)
1672 actorModel.Avatar = avatarModel 1673 actorModel.Avatar = avatarModel
1673 actorModel.Server = serverModel 1674 actorModel.Server = serverModel
1674 1675
@@ -1679,11 +1680,11 @@ export class VideoModel extends Model {
1679 if (!videosMemo[row.id]) { 1680 if (!videosMemo[row.id]) {
1680 // Build Channel 1681 // Build Channel
1681 const channel = row.VideoChannel 1682 const channel = row.VideoChannel
1682 const channelModel = new VideoChannelModel(pick(channel, [ 'id', 'name', 'description', 'actorId' ])) 1683 const channelModel = new VideoChannelModel(pick(channel, [ 'id', 'name', 'description', 'actorId' ]), buildOpts)
1683 channelModel.Actor = buildActor(channel.Actor) 1684 channelModel.Actor = buildActor(channel.Actor)
1684 1685
1685 const account = row.VideoChannel.Account 1686 const account = row.VideoChannel.Account
1686 const accountModel = new AccountModel(pick(account, [ 'id', 'name' ])) 1687 const accountModel = new AccountModel(pick(account, [ 'id', 'name' ]), buildOpts)
1687 accountModel.Actor = buildActor(account.Actor) 1688 accountModel.Actor = buildActor(account.Actor)
1688 1689
1689 channelModel.Account = accountModel 1690 channelModel.Account = accountModel
@@ -1704,28 +1705,28 @@ export class VideoModel extends Model {
1704 const videoModel = videosMemo[row.id] 1705 const videoModel = videosMemo[row.id]
1705 1706
1706 if (row.userVideoHistory?.id && !historyDone.has(row.userVideoHistory.id)) { 1707 if (row.userVideoHistory?.id && !historyDone.has(row.userVideoHistory.id)) {
1707 const historyModel = new UserVideoHistoryModel(pick(row.userVideoHistory, [ 'id', 'currentTime' ])) 1708 const historyModel = new UserVideoHistoryModel(pick(row.userVideoHistory, [ 'id', 'currentTime' ]), buildOpts)
1708 videoModel.UserVideoHistories.push(historyModel) 1709 videoModel.UserVideoHistories.push(historyModel)
1709 1710
1710 historyDone.add(row.userVideoHistory.id) 1711 historyDone.add(row.userVideoHistory.id)
1711 } 1712 }
1712 1713
1713 if (row.Thumbnails?.id && !thumbnailsDone.has(row.Thumbnails.id)) { 1714 if (row.Thumbnails?.id && !thumbnailsDone.has(row.Thumbnails.id)) {
1714 const thumbnailModel = new ThumbnailModel(pick(row.Thumbnails, [ 'id', 'type', 'filename' ])) 1715 const thumbnailModel = new ThumbnailModel(pick(row.Thumbnails, [ 'id', 'type', 'filename' ]), buildOpts)
1715 videoModel.Thumbnails.push(thumbnailModel) 1716 videoModel.Thumbnails.push(thumbnailModel)
1716 1717
1717 thumbnailsDone.add(row.Thumbnails.id) 1718 thumbnailsDone.add(row.Thumbnails.id)
1718 } 1719 }
1719 1720
1720 if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) { 1721 if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) {
1721 const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys)) 1722 const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys), buildOpts)
1722 videoModel.VideoFiles.push(videoFileModel) 1723 videoModel.VideoFiles.push(videoFileModel)
1723 1724
1724 videoFilesDone.add(row.VideoFiles.id) 1725 videoFilesDone.add(row.VideoFiles.id)
1725 } 1726 }
1726 1727
1727 if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) { 1728 if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) {
1728 const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys)) 1729 const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys), buildOpts)
1729 streamingPlaylist.VideoFiles = [] 1730 streamingPlaylist.VideoFiles = []
1730 1731
1731 videoModel.VideoStreamingPlaylists.push(streamingPlaylist) 1732 videoModel.VideoStreamingPlaylists.push(streamingPlaylist)
@@ -1736,7 +1737,7 @@ export class VideoModel extends Model {
1736 if (row.VideoStreamingPlaylists?.VideoFiles?.id && !videoFilesDone.has(row.VideoStreamingPlaylists.VideoFiles.id)) { 1737 if (row.VideoStreamingPlaylists?.VideoFiles?.id && !videoFilesDone.has(row.VideoStreamingPlaylists.VideoFiles.id)) {
1737 const streamingPlaylist = videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id] 1738 const streamingPlaylist = videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]
1738 1739
1739 const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys)) 1740 const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys), buildOpts)
1740 streamingPlaylist.VideoFiles.push(videoFileModel) 1741 streamingPlaylist.VideoFiles.push(videoFileModel)
1741 1742
1742 videoFilesDone.add(row.VideoStreamingPlaylists.VideoFiles.id) 1743 videoFilesDone.add(row.VideoStreamingPlaylists.VideoFiles.id)