From 668f864f5a50bd34ffd7c32c91bfff122118d4bf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Jun 2021 16:02:26 +0200 Subject: Fix live files include --- .../video/sql/shared/abstract-videos-model-query-builder.ts | 13 +++++-------- server/models/video/sql/shared/video-file-query-builder.ts | 4 ++-- server/models/video/sql/shared/video-model-builder.ts | 10 ++++++++-- server/models/video/sql/videos-model-list-query-builder.ts | 4 ++-- server/tests/api/live/live-permanent.ts | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) (limited to 'server') diff --git a/server/models/video/sql/shared/abstract-videos-model-query-builder.ts b/server/models/video/sql/shared/abstract-videos-model-query-builder.ts index d959cb5d0..0d7e64574 100644 --- a/server/models/video/sql/shared/abstract-videos-model-query-builder.ts +++ b/server/models/video/sql/shared/abstract-videos-model-query-builder.ts @@ -102,9 +102,8 @@ export class AbstractVideosModelQueryBuilder extends AbstractVideosQueryBuilder } } - protected includeWebtorrentFiles (required: boolean) { - const joinType = required ? 'INNER' : 'LEFT' - this.addJoin(joinType + ' JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"') + protected includeWebtorrentFiles () { + this.addJoin('LEFT JOIN "videoFile" AS "VideoFiles" ON "VideoFiles"."videoId" = "video"."id"') this.attributes = { ...this.attributes, @@ -113,15 +112,13 @@ export class AbstractVideosModelQueryBuilder extends AbstractVideosQueryBuilder } } - protected includeStreamingPlaylistFiles (required: boolean) { - const joinType = required ? 'INNER' : 'LEFT' - + protected includeStreamingPlaylistFiles () { this.addJoin( - joinType + ' JOIN "videoStreamingPlaylist" AS "VideoStreamingPlaylists" ON "VideoStreamingPlaylists"."videoId" = "video"."id"' + 'LEFT JOIN "videoStreamingPlaylist" AS "VideoStreamingPlaylists" ON "VideoStreamingPlaylists"."videoId" = "video"."id"' ) this.addJoin( - joinType + ' JOIN "videoFile" AS "VideoStreamingPlaylists->VideoFiles" ' + + 'LEFT JOIN "videoFile" AS "VideoStreamingPlaylists->VideoFiles" ' + 'ON "VideoStreamingPlaylists->VideoFiles"."videoStreamingPlaylistId" = "VideoStreamingPlaylists"."id"' ) diff --git a/server/models/video/sql/shared/video-file-query-builder.ts b/server/models/video/sql/shared/video-file-query-builder.ts index a62fa64f8..6b15c3b69 100644 --- a/server/models/video/sql/shared/video-file-query-builder.ts +++ b/server/models/video/sql/shared/video-file-query-builder.ts @@ -32,7 +32,7 @@ export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder { '"video"."id"': '' } - this.includeWebtorrentFiles(true) + this.includeWebtorrentFiles() if (this.shouldIncludeRedundancies(options)) { this.includeWebTorrentRedundancies() @@ -48,7 +48,7 @@ export class VideoFileQueryBuilder extends AbstractVideosModelQueryBuilder { '"video"."id"': '' } - this.includeStreamingPlaylistFiles(true) + this.includeStreamingPlaylistFiles() if (this.shouldIncludeRedundancies(options)) { this.includeStreamingPlaylistRedundancies() diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts index 467a9378a..cc71192c0 100644 --- a/server/models/video/sql/shared/video-model-builder.ts +++ b/server/models/video/sql/shared/video-model-builder.ts @@ -108,9 +108,12 @@ export class VideoModelBuilder { if (!rowsWebTorrentFiles) return for (const row of rowsWebTorrentFiles) { + const id = row['VideoFiles.id'] + if (!id) continue + const videoModel = this.videosMemo[row.id] this.addWebTorrentFile(row, videoModel) - this.addRedundancy(row, 'VideoFiles.RedundancyVideos', this.videoFileMemo[row['VideoFiles.id']]) + this.addRedundancy(row, 'VideoFiles.RedundancyVideos', this.videoFileMemo[id]) } } @@ -118,6 +121,9 @@ export class VideoModelBuilder { if (!rowsStreamingPlaylist) return for (const row of rowsStreamingPlaylist || []) { + const id = row['VideoStreamingPlaylists.id'] + if (!id) continue + const videoModel = this.videosMemo[row.id] this.addStreamingPlaylist(row, videoModel) @@ -125,7 +131,7 @@ export class VideoModelBuilder { this.addRedundancy( row, 'VideoStreamingPlaylists.RedundancyVideos', - this.videoStreamingPlaylistMemo[row['VideoStreamingPlaylists.id']] + this.videoStreamingPlaylistMemo[id] ) } } diff --git a/server/models/video/sql/videos-model-list-query-builder.ts b/server/models/video/sql/videos-model-list-query-builder.ts index 43040fc5e..e61c51de8 100644 --- a/server/models/video/sql/videos-model-list-query-builder.ts +++ b/server/models/video/sql/videos-model-list-query-builder.ts @@ -52,8 +52,8 @@ export class VideosModelListQueryBuilder extends AbstractVideosModelQueryBuilder this.includeThumbnails() if (options.withFiles) { - this.includeWebtorrentFiles(false) - this.includeStreamingPlaylistFiles(false) + this.includeWebtorrentFiles() + this.includeStreamingPlaylistFiles() } if (options.user) { diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 2b440dbd0..71b7d28a8 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -27,7 +27,7 @@ import { const expect = chai.expect -describe('Permenant live', function () { +describe('Permanent live', function () { let servers: ServerInfo[] = [] let videoUUID: string -- cgit v1.2.3