API_VERSION,
CONFIG,
CONSTRAINTS_FIELDS,
- HLS_PLAYLIST_DIRECTORY,
+ HLS_STREAMING_PLAYLIST_DIRECTORY,
HLS_REDUNDANCY_DIRECTORY,
PREVIEWS_SIZE,
REMOTE_SCHEME,
},
include: [
{
- model: VideoChannelModel.scope(VideoChannelScopeNames.SUMMARY)
+ model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] })
}
]
}
if (options.videoPlaylistId) {
query.include.push({
model: VideoPlaylistElementModel.unscoped(),
- required: true
+ required: true,
+ where: {
+ videoPlaylistId: options.videoPlaylistId
+ }
})
}
videoPlaylistId: options.videoPlaylistId
}
})
+
+ query.subQuery = false
}
if (options.filter || options.accountId || options.videoChannelId) {
if (ids.length === 0) return { data: [], total: count }
- // FIXME: typings
- const apiScope: any[] = [
- {
- method: [ ScopeNames.FOR_API, { ids, withFiles: options.withFiles } as ForAPIOptions ]
- }
- ]
-
- if (options.user) {
- apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })
- }
-
- const secondQuery = {
+ const secondQuery: IFindOptions<VideoModel> = {
offset: 0,
limit: query.limit,
attributes: query.attributes,
)
]
}
+
+ // FIXME: typing
+ const apiScope: any[] = []
+
+ if (options.user) {
+ apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })
+
+ // Even if the relation is n:m, we know that a user only have 0..1 video history
+ // So we won't have multiple rows for the same video
+ // A subquery adds some bugs in our query so disable it
+ secondQuery.subQuery = false
+ }
+
+ apiScope.push({
+ method: [
+ ScopeNames.FOR_API, {
+ ids, withFiles:
+ options.withFiles,
+ videoPlaylistId: options.videoPlaylistId
+ } as ForAPIOptions
+ ]
+ })
+
const rows = await VideoModel.scope(apiScope).findAll(secondQuery)
return {
}
removeStreamingPlaylist (isRedundancy = false) {
- const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_PLAYLIST_DIRECTORY
+ const baseDir = isRedundancy ? HLS_REDUNDANCY_DIRECTORY : HLS_STREAMING_PLAYLIST_DIRECTORY
const filePath = join(baseDir, this.uuid)
return remove(filePath)