aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-05 10:29:35 +0200
committerChocobozzz <me@florianbigard.com>2022-05-05 10:29:35 +0200
commitbae616273d455d225d131eb17c56db6c20a0b6b3 (patch)
treeed2174122d092320cea34c4ae522da6f2131f968 /server/models/utils.ts
parentd493e2d4bf0ace177d15e9173d1c02df8c100558 (diff)
downloadPeerTube-bae616273d455d225d131eb17c56db6c20a0b6b3.tar.gz
PeerTube-bae616273d455d225d131eb17c56db6c20a0b6b3.tar.zst
PeerTube-bae616273d455d225d131eb17c56db6c20a0b6b3.zip
Convert followers/following in raw SQL queries
Prevent weird bug in SQL generation
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 70bfbdb8b..b57290aff 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -87,12 +87,12 @@ function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'i
87 return [ firstSort, lastSort ] 87 return [ firstSort, lastSort ]
88} 88}
89 89
90function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { 90function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
91 const { direction, field } = buildDirectionAndField(value) 91 const { direction, field } = buildDirectionAndField(value)
92 92
93 if (field === 'redundancyAllowed') { 93 if (field === 'redundancyAllowed') {
94 return [ 94 return [
95 [ 'ActorFollowing', 'Server', 'redundancyAllowed', direction ], 95 [ 'ActorFollowing.Server.redundancyAllowed', direction ],
96 lastSort 96 lastSort
97 ] 97 ]
98 } 98 }
@@ -197,6 +197,12 @@ function parseAggregateResult (result: any) {
197 return total 197 return total
198} 198}
199 199
200function parseRowCountResult (result: any) {
201 if (result.length !== 0) return result[0].total
202
203 return 0
204}
205
200function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) { 206function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) {
201 return stringArr.map(t => { 207 return stringArr.map(t => {
202 return t === null 208 return t === null
@@ -263,10 +269,11 @@ export {
263 buildWhereIdOrUUID, 269 buildWhereIdOrUUID,
264 isOutdated, 270 isOutdated,
265 parseAggregateResult, 271 parseAggregateResult,
266 getFollowsSort, 272 getInstanceFollowsSort,
267 buildDirectionAndField, 273 buildDirectionAndField,
268 createSafeIn, 274 createSafeIn,
269 searchAttribute 275 searchAttribute,
276 parseRowCountResult
270} 277}
271 278
272// --------------------------------------------------------------------------- 279// ---------------------------------------------------------------------------