aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/sql/shared/video-file-query-builder.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-10 16:57:13 +0200
committerChocobozzz <me@florianbigard.com>2021-06-11 09:31:59 +0200
commit1d43c3a613c72d69f7360fee9e5bfe6f662d62f7 (patch)
treed4ba891ffdb1182e39620c06feff1503365d66b5 /server/models/video/sql/shared/video-file-query-builder.ts
parentd9bf974f5df787bbeaab5b04949ca91a2b3ca2a3 (diff)
downloadPeerTube-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-file-query-builder.ts')
-rw-r--r--server/models/video/sql/shared/video-file-query-builder.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/server/models/video/sql/shared/video-file-query-builder.ts b/server/models/video/sql/shared/video-file-query-builder.ts
new file mode 100644
index 000000000..29b11a298
--- /dev/null
+++ b/server/models/video/sql/shared/video-file-query-builder.ts
@@ -0,0 +1,66 @@
1import { Sequelize } from 'sequelize'
2import { BuildVideoGetQueryOptions } from '../video-model-get-query-builder'
3import { AbstractVideosModelQueryBuilder } from './abstract-videos-model-query-builder'
4
5/**
6 *
7 * Fetch files (webtorrent and streaming playlist) according to a video
8 *
9 */
10
11export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder {
12 protected attributes: { [key: string]: string }
13 protected joins: string[] = []
14
15 constructor (protected readonly sequelize: Sequelize) {
16 super('get')
17 }
18
19 queryWebTorrentVideos (options: BuildVideoGetQueryOptions) {
20 this.buildWebtorrentFilesQuery(options)
21
22 return this.runQuery(options.transaction, true)
23 }
24
25 queryStreamingPlaylistVideos (options: BuildVideoGetQueryOptions) {
26 this.buildVideoStreamingPlaylistFilesQuery(options)
27
28 return this.runQuery(options.transaction, true)
29 }
30
31 private buildWebtorrentFilesQuery (options: BuildVideoGetQueryOptions) {
32 this.attributes = {
33 '"video"."id"': ''
34 }
35
36 this.includeWebtorrentFiles(true)
37
38 if (options.forGetAPI === true) {
39 this.includeWebTorrentRedundancies()
40 }
41
42 this.whereId(options.id)
43
44 this.query = this.buildQuery()
45 }
46
47 private buildVideoStreamingPlaylistFilesQuery (options: BuildVideoGetQueryOptions) {
48 this.attributes = {
49 '"video"."id"': ''
50 }
51
52 this.includeStreamingPlaylistFiles(true)
53
54 if (options.forGetAPI === true) {
55 this.includeStreamingPlaylistRedundancies()
56 }
57
58 this.whereId(options.id)
59
60 this.query = this.buildQuery()
61 }
62
63 private buildQuery () {
64 return `${this.buildSelect()} FROM "video" ${this.joins.join(' ')} ${this.where}`
65 }
66}