1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Convert followers/following in raw SQL queries

Prevent weird bug in SQL generation
This commit is contained in:
Chocobozzz 2022-05-05 10:29:35 +02:00
parent d493e2d4bf
commit bae616273d
No known key found for this signature in database
GPG key ID: 583A612D890159BE
11 changed files with 338 additions and 145 deletions

View file

@ -87,12 +87,12 @@ function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'i
return [ firstSort, lastSort ]
}
function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildDirectionAndField(value)
if (field === 'redundancyAllowed') {
return [
[ 'ActorFollowing', 'Server', 'redundancyAllowed', direction ],
[ 'ActorFollowing.Server.redundancyAllowed', direction ],
lastSort
]
}
@ -197,6 +197,12 @@ function parseAggregateResult (result: any) {
return total
}
function parseRowCountResult (result: any) {
if (result.length !== 0) return result[0].total
return 0
}
function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) {
return stringArr.map(t => {
return t === null
@ -263,10 +269,11 @@ export {
buildWhereIdOrUUID,
isOutdated,
parseAggregateResult,
getFollowsSort,
getInstanceFollowsSort,
buildDirectionAndField,
createSafeIn,
searchAttribute
searchAttribute,
parseRowCountResult
}
// ---------------------------------------------------------------------------