X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=e27625bc862c8a20504b0e12c0224d9539c598b3;hb=35f676e5d3e5e242e84ed63da2cc78117079c7cb;hp=a06d578312197e7d0b6e9a8d2cf00e6591fbf864;hpb=49cff3a4c950b22ae13f345dc4eab803d96a236e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index a06d57831..e27625bc8 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,5 +1,4 @@ -import { literal, Op, OrderItem } from 'sequelize' -import { Model, Sequelize } from 'sequelize-typescript' +import { literal, Op, OrderItem, Sequelize } from 'sequelize' import { Col } from 'sequelize/types/lib/utils' import validator from 'validator' @@ -54,6 +53,14 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or [ Sequelize.col('VideoModel.views'), direction ], + lastSort + ] + } else if (field === 'publishedAt') { + return [ + [ 'ScheduleVideoUpdate', 'updateAt', direction + ' NULLS LAST' ], + + [ Sequelize.col('VideoModel.publishedAt'), direction ], + lastSort ] } @@ -113,7 +120,8 @@ function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldN function buildTrigramSearchIndex (indexName: string, attribute: string) { return { name: indexName, - fields: [ Sequelize.literal('lower(immutable_unaccent(' + attribute + '))') as any ], + // FIXME: gin_trgm_ops is not taken into account in Sequelize 6, so adding it ourselves in the literal function + fields: [ Sequelize.literal('lower(immutable_unaccent(' + attribute + ')) gin_trgm_ops') as any ], using: 'gin', operator: 'gin_trgm_ops' } @@ -133,7 +141,7 @@ function buildBlockedAccountSQL (blockerIds: number[]) { const blockerIdsString = blockerIds.join(', ') return 'SELECT "targetAccountId" AS "id" FROM "accountBlocklist" WHERE "accountId" IN (' + blockerIdsString + ')' + - ' UNION ALL ' + + ' UNION ' + 'SELECT "account"."id" AS "id" FROM account INNER JOIN "actor" ON account."actorId" = actor.id ' + 'INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ' + 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' @@ -186,11 +194,11 @@ function parseAggregateResult (result: any) { return total } -const createSafeIn = (model: typeof Model, stringArr: (string | number)[]) => { +function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) { return stringArr.map(t => { return t === null ? null - : model.sequelize.escape('' + t) + : sequelize.escape('' + t) }).join(', ') }