aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-video-rate.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-26 16:26:27 +0100
committerChocobozzz <me@florianbigard.com>2021-03-03 10:08:08 +0100
commit74d249bc1346c7cfaac7ee49bebbebcf2a01f82a (patch)
treed47bd163ae57ed8f15b445296634cc04f4f67b6f /server/models/account/account-video-rate.ts
parent095e2258043fcff8a79ab082d11edfbd8f13a8e2 (diff)
downloadPeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.gz
PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.zst
PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.zip
Add ability to cleanup remote AP interactions
Diffstat (limited to 'server/models/account/account-video-rate.ts')
-rw-r--r--server/models/account/account-video-rate.ts30
1 files changed, 14 insertions, 16 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts
index d9c529491..801f76bba 100644
--- a/server/models/account/account-video-rate.ts
+++ b/server/models/account/account-video-rate.ts
@@ -146,10 +146,22 @@ export class AccountVideoRateModel extends Model {
146 return AccountVideoRateModel.findAndCountAll(query) 146 return AccountVideoRateModel.findAndCountAll(query)
147 } 147 }
148 148
149 static listRemoteRateUrlsOfLocalVideos () {
150 const query = `SELECT "accountVideoRate".url FROM "accountVideoRate" ` +
151 `INNER JOIN account ON account.id = "accountVideoRate"."accountId" ` +
152 `INNER JOIN actor ON actor.id = account."actorId" AND actor."serverId" IS NOT NULL ` +
153 `INNER JOIN video ON video.id = "accountVideoRate"."videoId" AND video.remote IS FALSE`
154
155 return AccountVideoRateModel.sequelize.query<{ url: string }>(query, {
156 type: QueryTypes.SELECT,
157 raw: true
158 }).then(rows => rows.map(r => r.url))
159 }
160
149 static loadLocalAndPopulateVideo ( 161 static loadLocalAndPopulateVideo (
150 rateType: VideoRateType, 162 rateType: VideoRateType,
151 accountName: string, 163 accountName: string,
152 videoId: number | string, 164 videoId: number,
153 t?: Transaction 165 t?: Transaction
154 ): Promise<MAccountVideoRateAccountVideo> { 166 ): Promise<MAccountVideoRateAccountVideo> {
155 const options: FindOptions = { 167 const options: FindOptions = {
@@ -241,21 +253,7 @@ export class AccountVideoRateModel extends Model {
241 253
242 await AccountVideoRateModel.destroy(query) 254 await AccountVideoRateModel.destroy(query)
243 255
244 const field = type === 'like' 256 return VideoModel.updateRatesOf(videoId, type, t)
245 ? 'likes'
246 : 'dislikes'
247
248 const rawQuery = `UPDATE "video" SET "${field}" = ` +
249 '(' +
250 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' +
251 ') ' +
252 'WHERE "video"."id" = :videoId'
253
254 return AccountVideoRateModel.sequelize.query(rawQuery, {
255 transaction: t,
256 replacements: { videoId, rateType: type },
257 type: QueryTypes.UPDATE
258 })
259 }) 257 })
260 } 258 }
261 259