diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-10 16:57:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-11 09:31:59 +0200 |
commit | 1d43c3a613c72d69f7360fee9e5bfe6f662d62f7 (patch) | |
tree | d4ba891ffdb1182e39620c06feff1503365d66b5 /server/models/video/sql/shared/video-model-builder.ts | |
parent | d9bf974f5df787bbeaab5b04949ca91a2b3ca2a3 (diff) | |
download | PeerTube-1d43c3a613c72d69f7360fee9e5bfe6f662d62f7.tar.gz PeerTube-1d43c3a613c72d69f7360fee9e5bfe6f662d62f7.tar.zst PeerTube-1d43c3a613c72d69f7360fee9e5bfe6f662d62f7.zip |
Use separate queries for video files
Diffstat (limited to 'server/models/video/sql/shared/video-model-builder.ts')
-rw-r--r-- | server/models/video/sql/shared/video-model-builder.ts | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts index 9719f6d2e..627ea6443 100644 --- a/server/models/video/sql/shared/video-model-builder.ts +++ b/server/models/video/sql/shared/video-model-builder.ts | |||
@@ -17,6 +17,12 @@ import { VideoLiveModel } from '../../video-live' | |||
17 | import { VideoStreamingPlaylistModel } from '../../video-streaming-playlist' | 17 | import { VideoStreamingPlaylistModel } from '../../video-streaming-playlist' |
18 | import { VideoAttributes } from './video-attributes' | 18 | import { VideoAttributes } from './video-attributes' |
19 | 19 | ||
20 | /** | ||
21 | * | ||
22 | * Build video models from SQL rows | ||
23 | * | ||
24 | */ | ||
25 | |||
20 | export class VideoModelBuilder { | 26 | export class VideoModelBuilder { |
21 | private videosMemo: { [ id: number ]: VideoModel } | 27 | private videosMemo: { [ id: number ]: VideoModel } |
22 | private videoStreamingPlaylistMemo: { [ id: number ]: VideoStreamingPlaylistModel } | 28 | private videoStreamingPlaylistMemo: { [ id: number ]: VideoStreamingPlaylistModel } |
@@ -43,7 +49,7 @@ export class VideoModelBuilder { | |||
43 | 49 | ||
44 | } | 50 | } |
45 | 51 | ||
46 | buildVideosFromRows (rows: any[]) { | 52 | buildVideosFromRows (rows: any[], rowsWebtorrentFiles?: any[], rowsStreamingPlaylist?: any[]) { |
47 | this.reinit() | 53 | this.reinit() |
48 | 54 | ||
49 | for (const row of rows) { | 55 | for (const row of rows) { |
@@ -53,10 +59,15 @@ export class VideoModelBuilder { | |||
53 | 59 | ||
54 | this.setUserHistory(row, videoModel) | 60 | this.setUserHistory(row, videoModel) |
55 | this.addThumbnail(row, videoModel) | 61 | this.addThumbnail(row, videoModel) |
56 | this.addWebTorrentFile(row, videoModel) | ||
57 | 62 | ||
58 | this.addStreamingPlaylist(row, videoModel) | 63 | if (!rowsWebtorrentFiles) { |
59 | this.addStreamingPlaylistFile(row) | 64 | this.addWebTorrentFile(row, videoModel) |
65 | } | ||
66 | |||
67 | if (!rowsStreamingPlaylist) { | ||
68 | this.addStreamingPlaylist(row, videoModel) | ||
69 | this.addStreamingPlaylistFile(row) | ||
70 | } | ||
60 | 71 | ||
61 | if (this.mode === 'get') { | 72 | if (this.mode === 'get') { |
62 | this.addTag(row, videoModel) | 73 | this.addTag(row, videoModel) |
@@ -65,16 +76,30 @@ export class VideoModelBuilder { | |||
65 | this.setScheduleVideoUpdate(row, videoModel) | 76 | this.setScheduleVideoUpdate(row, videoModel) |
66 | this.setLive(row, videoModel) | 77 | this.setLive(row, videoModel) |
67 | 78 | ||
68 | if (row.VideoFiles.id) { | 79 | if (!rowsWebtorrentFiles && row.VideoFiles.id) { |
69 | this.addRedundancy(row.VideoFiles.RedundancyVideos, this.videoFileMemo[row.VideoFiles.id]) | 80 | this.addRedundancy(row.VideoFiles.RedundancyVideos, this.videoFileMemo[row.VideoFiles.id]) |
70 | } | 81 | } |
71 | 82 | ||
72 | if (row.VideoStreamingPlaylists.id) { | 83 | if (!rowsStreamingPlaylist && row.VideoStreamingPlaylists.id) { |
73 | this.addRedundancy(row.VideoStreamingPlaylists.RedundancyVideos, this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) | 84 | this.addRedundancy(row.VideoStreamingPlaylists.RedundancyVideos, this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) |
74 | } | 85 | } |
75 | } | 86 | } |
76 | } | 87 | } |
77 | 88 | ||
89 | for (const row of rowsWebtorrentFiles || []) { | ||
90 | const videoModel = this.videosMemo[row.id] | ||
91 | this.addWebTorrentFile(row, videoModel) | ||
92 | this.addRedundancy(row.VideoFiles.RedundancyVideos, this.videoFileMemo[row.VideoFiles.id]) | ||
93 | } | ||
94 | |||
95 | for (const row of rowsStreamingPlaylist || []) { | ||
96 | const videoModel = this.videosMemo[row.id] | ||
97 | |||
98 | this.addStreamingPlaylist(row, videoModel) | ||
99 | this.addStreamingPlaylistFile(row) | ||
100 | this.addRedundancy(row.VideoStreamingPlaylists.RedundancyVideos, this.videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) | ||
101 | } | ||
102 | |||
78 | return this.videos | 103 | return this.videos |
79 | } | 104 | } |
80 | 105 | ||