Rewrite video list in raw SQL

This commit is contained in:
Chocobozzz 2020-03-05 15:04:57 +01:00
parent f8cce49c3f
commit 5f3e2425f1
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 428 additions and 434 deletions

View file

@ -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 }
}