aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-video-rate.ts
diff options
context:
space:
mode:
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