diff options
author | Chocobozzz <me@florianbigard.com> | 2022-05-05 10:29:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-05-05 10:29:35 +0200 |
commit | bae616273d455d225d131eb17c56db6c20a0b6b3 (patch) | |
tree | ed2174122d092320cea34c4ae522da6f2131f968 /server/models/utils.ts | |
parent | d493e2d4bf0ace177d15e9173d1c02df8c100558 (diff) | |
download | PeerTube-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.ts | 15 |
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 | ||
90 | function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { | 90 | function 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 | ||
200 | function parseRowCountResult (result: any) { | ||
201 | if (result.length !== 0) return result[0].total | ||
202 | |||
203 | return 0 | ||
204 | } | ||
205 | |||
200 | function createSafeIn (sequelize: Sequelize, stringArr: (string | number)[]) { | 206 | function 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 | // --------------------------------------------------------------------------- |