From 2ba92871319d7af63472c1380664a9f9eeb1c690 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 16:23:02 +0100 Subject: Cleanup invalid rates/comments/shares --- server/models/video/video-share.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server/models/video/video-share.ts') 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 @@ import * as Sequelize from 'sequelize' +import { Op } from 'sequelize' import * as Bluebird from 'bluebird' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' @@ -200,4 +201,17 @@ export class VideoShareModel extends Model { return VideoShareModel.findAndCountAll(query) } + + static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) { + const query = { + where: { + updatedAt: { + [Op.lt]: beforeUpdatedAt + }, + videoId + } + } + + return VideoShareModel.destroy(query) + } } -- cgit v1.2.3