From 5f3e2425f1c64d93860a0c3341de9b361b3c1f1f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 5 Mar 2020 15:04:57 +0100 Subject: Rewrite video list in raw SQL --- server/models/utils.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'server/models/utils.ts') diff --git a/server/models/utils.ts b/server/models/utils.ts index f7afb8d4b..674ddcbe4 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -156,8 +156,11 @@ function parseAggregateResult (result: any) { } const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { - return stringArr.map(t => model.sequelize.escape('' + t)) - .join(', ') + return stringArr.map(t => { + return t === null + ? null + : model.sequelize.escape('' + t) + }).join(', ') } function buildLocalAccountIdsIn () { @@ -172,6 +175,21 @@ function buildLocalActorIdsIn () { ) } +function buildDirectionAndField (value: string) { + let field: string + let direction: 'ASC' | 'DESC' + + if (value.substring(0, 1) === '-') { + direction = 'DESC' + field = value.substring(1) + } else { + direction = 'ASC' + field = value + } + + return { direction, field } +} + // --------------------------------------------------------------------------- export { @@ -191,6 +209,7 @@ export { isOutdated, parseAggregateResult, getFollowsSort, + buildDirectionAndField, createSafeIn } @@ -203,18 +222,3 @@ function searchTrigramNormalizeValue (value: string) { function searchTrigramNormalizeCol (col: string) { return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', Sequelize.col(col))) } - -function buildDirectionAndField (value: string) { - let field: string - let direction: 'ASC' | 'DESC' - - if (value.substring(0, 1) === '-') { - direction = 'DESC' - field = value.substring(1) - } else { - direction = 'ASC' - field = value - } - - return { direction, field } -} -- cgit v1.2.3