X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Factivitypub-http-fetcher.ts;h=23d33c26fd47e5e51779cb05a944510d3f32dc1c;hb=2ba92871319d7af63472c1380664a9f9eeb1c690;hp=52225f64fd316cc894d98806f8f80d16694e2716;hpb=d74d29ad9e35929491cf37223398d2535ab23de0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index 52225f64f..23d33c26f 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts @@ -1,4 +1,5 @@ import * as Bull from 'bull' +import * as Bluebird from 'bluebird' import { logger } from '../../../helpers/logger' import { processActivities } from '../../activitypub/process' import { addVideoComments } from '../../activitypub/video-comments' @@ -7,6 +8,9 @@ import { VideoModel } from '../../../models/video/video' import { addVideoShares, createRates } from '../../activitypub' import { createAccountPlaylists } from '../../activitypub/playlist' import { AccountModel } from '../../../models/account/account' +import { AccountVideoRateModel } from '../../../models/account/account-video-rate' +import { VideoShareModel } from '../../../models/video/video-share' +import { VideoCommentModel } from '../../../models/video/video-comment' type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | 'account-playlists' @@ -37,7 +41,14 @@ async function processActivityPubHttpFetcher (job: Bull.Job) { 'account-playlists': items => createAccountPlaylists(items, account) } - return crawlCollectionPage(payload.uri, fetcherType[payload.type]) + const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird } = { + 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate), + 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate), + 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), + 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) + } + + return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type]) } // ---------------------------------------------------------------------------