From 15d4ee04a94230e1ea83c2959a1981105699ba22 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 May 2017 19:09:55 +0200 Subject: [PATCH] Server: little refractoring when listing videos --- server/models/video.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/models/video.js b/server/models/video.js index 0eef4114c..029cb6d7c 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -544,11 +544,7 @@ function listForApi (start, count, sort, callback) { this.sequelize.models.Tag ], - where: { - id: { $notIn: this.sequelize.literal( - '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")' - )} - } + where: createBaseVideosWhere.call(this) } return this.findAndCountAll(query).asCallback(function (err, result) { @@ -656,11 +652,7 @@ function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort, } const query = { - where: { - id: { $notIn: this.sequelize.literal( - '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")' - )} - }, + where: createBaseVideosWhere.call(this), offset: start, limit: count, distinct: true, // For the count, a video can have many tags @@ -715,6 +707,16 @@ function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort, // --------------------------------------------------------------------------- +function createBaseVideosWhere () { + return { + id: { + $notIn: this.sequelize.literal( + '(SELECT "BlacklistedVideos"."videoId" FROM "BlacklistedVideos")' + ) + } + } +} + function removeThumbnail (video, callback) { const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()) fs.unlink(thumbnailPath, callback) -- 2.41.0