Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81b46cb

Browse files
committed
Optimize videos list API endpoint
1 parent 9162476 commit 81b46cb

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

server/models/video/video.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,17 +1658,18 @@ export class VideoModel extends Model {
16581658
'createdAt',
16591659
'updatedAt'
16601660
]
1661+
const buildOpts = { raw: true }
16611662

16621663
function buildActor (rowActor: any) {
16631664
const avatarModel = rowActor.Avatar.id !== null
1664-
? new AvatarModel(pick(rowActor.Avatar, avatarKeys))
1665+
? new AvatarModel(pick(rowActor.Avatar, avatarKeys), buildOpts)
16651666
: null
16661667

16671668
const serverModel = rowActor.Server.id !== null
1668-
? new ServerModel(pick(rowActor.Server, serverKeys))
1669+
? new ServerModel(pick(rowActor.Server, serverKeys), buildOpts)
16691670
: null
16701671

1671-
const actorModel = new ActorModel(pick(rowActor, actorKeys))
1672+
const actorModel = new ActorModel(pick(rowActor, actorKeys), buildOpts)
16721673
actorModel.Avatar = avatarModel
16731674
actorModel.Server = serverModel
16741675

@@ -1679,11 +1680,11 @@ export class VideoModel extends Model {
16791680
if (!videosMemo[row.id]) {
16801681
// Build Channel
16811682
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)
16831684
channelModel.Actor = buildActor(channel.Actor)
16841685

16851686
const account = row.VideoChannel.Account
1686-
const accountModel = new AccountModel(pick(account, [ 'id', 'name' ]))
1687+
const accountModel = new AccountModel(pick(account, [ 'id', 'name' ]), buildOpts)
16871688
accountModel.Actor = buildActor(account.Actor)
16881689

16891690
channelModel.Account = accountModel
@@ -1704,28 +1705,28 @@ export class VideoModel extends Model {
17041705
const videoModel = videosMemo[row.id]
17051706

17061707
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)
17081709
videoModel.UserVideoHistories.push(historyModel)
17091710

17101711
historyDone.add(row.userVideoHistory.id)
17111712
}
17121713

17131714
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)
17151716
videoModel.Thumbnails.push(thumbnailModel)
17161717

17171718
thumbnailsDone.add(row.Thumbnails.id)
17181719
}
17191720

17201721
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)
17221723
videoModel.VideoFiles.push(videoFileModel)
17231724

17241725
videoFilesDone.add(row.VideoFiles.id)
17251726
}
17261727

17271728
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)
17291730
streamingPlaylist.VideoFiles = []
17301731

17311732
videoModel.VideoStreamingPlaylists.push(streamingPlaylist)
@@ -1736,7 +1737,7 @@ export class VideoModel extends Model {
17361737
if (row.VideoStreamingPlaylists?.VideoFiles?.id && !videoFilesDone.has(row.VideoStreamingPlaylists.VideoFiles.id)) {
17371738
const streamingPlaylist = videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]
17381739

1739-
const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys))
1740+
const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys), buildOpts)
17401741
streamingPlaylist.VideoFiles.push(videoFileModel)
17411742

17421743
videoFilesDone.add(row.VideoStreamingPlaylists.VideoFiles.id)

0 commit comments

Comments
 (0)