diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 16:23:02 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 16:23:02 +0100 |
commit | 2ba92871319d7af63472c1380664a9f9eeb1c690 (patch) | |
tree | d593b2dfea29a8171b9f6afaaef076321f5edf71 /server/models/video/video-share.ts | |
parent | d74d29ad9e35929491cf37223398d2535ab23de0 (diff) | |
download | PeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.tar.gz PeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.tar.zst PeerTube-2ba92871319d7af63472c1380664a9f9eeb1c690.zip |
Cleanup invalid rates/comments/shares
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r-- | server/models/video/video-share.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 7df0ed18d..fb52b35d9 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { Op } from 'sequelize' | ||
2 | import * as Bluebird from 'bluebird' | 3 | import * as Bluebird from 'bluebird' |
3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 4 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 5 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
@@ -200,4 +201,17 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
200 | 201 | ||
201 | return VideoShareModel.findAndCountAll(query) | 202 | return VideoShareModel.findAndCountAll(query) |
202 | } | 203 | } |
204 | |||
205 | static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) { | ||
206 | const query = { | ||
207 | where: { | ||
208 | updatedAt: { | ||
209 | [Op.lt]: beforeUpdatedAt | ||
210 | }, | ||
211 | videoId | ||
212 | } | ||
213 | } | ||
214 | |||
215 | return VideoShareModel.destroy(query) | ||
216 | } | ||
203 | } | 217 | } |