diff options
Diffstat (limited to 'server/models/video/sql/video/videos-model-list-query-builder.ts')
-rw-r--r-- | server/models/video/sql/video/videos-model-list-query-builder.ts | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/server/models/video/sql/video/videos-model-list-query-builder.ts b/server/models/video/sql/video/videos-model-list-query-builder.ts index 2a4afc389..4fe6bc321 100644 --- a/server/models/video/sql/video/videos-model-list-query-builder.ts +++ b/server/models/video/sql/video/videos-model-list-query-builder.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import { VideoInclude } from '@shared/models' | 1 | import { pick } from 'lodash' |
2 | import { Sequelize } from 'sequelize' | 2 | import { Sequelize } from 'sequelize' |
3 | import { VideoInclude } from '@shared/models' | ||
3 | import { AbstractVideoQueryBuilder } from './shared/abstract-video-query-builder' | 4 | import { AbstractVideoQueryBuilder } from './shared/abstract-video-query-builder' |
5 | import { VideoFileQueryBuilder } from './shared/video-file-query-builder' | ||
4 | import { VideoModelBuilder } from './shared/video-model-builder' | 6 | import { VideoModelBuilder } from './shared/video-model-builder' |
5 | import { BuildVideosListQueryOptions, VideosIdListQueryBuilder } from './videos-id-list-query-builder' | 7 | import { BuildVideosListQueryOptions, VideosIdListQueryBuilder } from './videos-id-list-query-builder' |
6 | 8 | ||
@@ -16,20 +18,46 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { | |||
16 | private innerQuery: string | 18 | private innerQuery: string |
17 | private innerSort: string | 19 | private innerSort: string |
18 | 20 | ||
21 | webtorrentFilesQueryBuilder: VideoFileQueryBuilder | ||
22 | streamingPlaylistFilesQueryBuilder: VideoFileQueryBuilder | ||
23 | |||
19 | private readonly videoModelBuilder: VideoModelBuilder | 24 | private readonly videoModelBuilder: VideoModelBuilder |
20 | 25 | ||
21 | constructor (protected readonly sequelize: Sequelize) { | 26 | constructor (protected readonly sequelize: Sequelize) { |
22 | super(sequelize, 'list') | 27 | super(sequelize, 'list') |
23 | 28 | ||
24 | this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) | 29 | this.videoModelBuilder = new VideoModelBuilder(this.mode, this.tables) |
30 | this.webtorrentFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | ||
31 | this.streamingPlaylistFilesQueryBuilder = new VideoFileQueryBuilder(sequelize) | ||
25 | } | 32 | } |
26 | 33 | ||
27 | queryVideos (options: BuildVideosListQueryOptions) { | 34 | async queryVideos (options: BuildVideosListQueryOptions) { |
28 | this.buildInnerQuery(options) | 35 | this.buildInnerQuery(options) |
29 | this.buildMainQuery(options) | 36 | this.buildMainQuery(options) |
30 | 37 | ||
31 | return this.runQuery() | 38 | const rows = await this.runQuery() |
32 | .then(rows => this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include })) | 39 | |
40 | if (options.include & VideoInclude.FILES) { | ||
41 | const videoIds = Array.from(new Set(rows.map(r => r.id))) | ||
42 | |||
43 | if (videoIds.length !== 0) { | ||
44 | const fileQueryOptions = { | ||
45 | ...pick(options, [ 'transaction', 'logging' ]), | ||
46 | |||
47 | ids: videoIds, | ||
48 | includeRedundancy: false | ||
49 | } | ||
50 | |||
51 | const [ rowsWebTorrentFiles, rowsStreamingPlaylist ] = await Promise.all([ | ||
52 | this.webtorrentFilesQueryBuilder.queryWebTorrentVideos(fileQueryOptions), | ||
53 | this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(fileQueryOptions) | ||
54 | ]) | ||
55 | |||
56 | return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include, rowsStreamingPlaylist, rowsWebTorrentFiles }) | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include }) | ||
33 | } | 61 | } |
34 | 62 | ||
35 | private buildInnerQuery (options: BuildVideosListQueryOptions) { | 63 | private buildInnerQuery (options: BuildVideosListQueryOptions) { |
@@ -52,11 +80,6 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder { | |||
52 | this.includeAccounts() | 80 | this.includeAccounts() |
53 | this.includeThumbnails() | 81 | this.includeThumbnails() |
54 | 82 | ||
55 | if (options.include & VideoInclude.FILES) { | ||
56 | this.includeWebtorrentFiles() | ||
57 | this.includeStreamingPlaylistFiles() | ||
58 | } | ||
59 | |||
60 | if (options.user) { | 83 | if (options.user) { |
61 | this.includeUserHistory(options.user.id) | 84 | this.includeUserHistory(options.user.id) |
62 | } | 85 | } |