1
0
Fork 0

Don't forward view, send updates instead

To avoid inconsistencies in the federation, now the origin server will
tell other instances what is the correct number of views
This commit is contained in:
Chocobozzz 2018-11-15 16:18:12 +01:00
parent 650e3d5ce3
commit 030177d246
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 17 additions and 17 deletions

View file

@ -405,7 +405,11 @@ async function viewVideo (req: express.Request, res: express.Response) {
const serverActor = await getServerActor() const serverActor = await getServerActor()
// Send the event to the origin server
// If we own the video, we'll send an update event when we'll process the views (in our job queue)
if (videoInstance.isOwned() === false) {
await sendCreateView(serverActor, videoInstance, undefined) await sendCreateView(serverActor, videoInstance, undefined)
}
return res.status(204).end() return res.status(204).end()
} }

View file

@ -13,7 +13,8 @@ import { forwardVideoRelatedActivity } from '../send/utils'
import { Redis } from '../../redis' import { Redis } from '../../redis'
import { createOrUpdateCacheFile } from '../cache-file' import { createOrUpdateCacheFile } from '../cache-file'
import { immutableAssign } from '../../../tests/utils' import { immutableAssign } from '../../../tests/utils'
import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' import { getVideoDislikeActivityPubUrl } from '../url'
import { VideoModel } from '../../../models/video/video'
async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) { async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
const activityObject = activity.object const activityObject = activity.object
@ -87,19 +88,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea
async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { async function processCreateView (byActor: ActorModel, activity: ActivityCreate) {
const view = activity.object as ViewObject const view = activity.object as ViewObject
const options = { const video = await VideoModel.loadByUrl(view.object)
videoObject: view.object, if (!video || video.isOwned() === false) return
fetchType: 'only-video' as 'only-video'
}
const { video } = await getOrCreateVideoAndAccountAndChannel(options)
await Redis.Instance.addVideoView(video.id) await Redis.Instance.addVideoView(video.id)
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
}
} }
async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) { async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) {

View file

@ -3,8 +3,9 @@ import { logger } from '../../../helpers/logger'
import { VideoModel } from '../../../models/video/video' import { VideoModel } from '../../../models/video/video'
import { VideoViewModel } from '../../../models/video/video-views' import { VideoViewModel } from '../../../models/video/video-views'
import { isTestInstance } from '../../../helpers/core-utils' import { isTestInstance } from '../../../helpers/core-utils'
import { federateVideoIfNeeded } from '../../activitypub'
async function processVideosViewsViews () { async function processVideosViews () {
const lastHour = new Date() const lastHour = new Date()
// In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour
@ -36,6 +37,9 @@ async function processVideosViewsViews () {
views, views,
videoId videoId
}) })
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
await federateVideoIfNeeded(video, false)
} catch (err) { } catch (err) {
logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour)
} }
@ -51,5 +55,5 @@ async function processVideosViewsViews () {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
processVideosViewsViews processVideosViews
} }

View file

@ -10,7 +10,7 @@ import { EmailPayload, processEmail } from './handlers/email'
import { processVideoFile, processVideoFileImport, VideoFileImportPayload, VideoFilePayload } from './handlers/video-file' import { processVideoFile, processVideoFileImport, VideoFileImportPayload, VideoFilePayload } from './handlers/video-file'
import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow'
import { processVideoImport, VideoImportPayload } from './handlers/video-import' import { processVideoImport, VideoImportPayload } from './handlers/video-import'
import { processVideosViewsViews } from './handlers/video-views' import { processVideosViews } from './handlers/video-views'
type CreateJobArgument = type CreateJobArgument =
{ type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
@ -32,7 +32,7 @@ const handlers: { [ id in JobType ]: (job: Bull.Job) => Promise<any>} = {
'video-file': processVideoFile, 'video-file': processVideoFile,
'email': processEmail, 'email': processEmail,
'video-import': processVideoImport, 'video-import': processVideoImport,
'videos-views': processVideosViewsViews 'videos-views': processVideosViews
} }
const jobTypes: JobType[] = [ const jobTypes: JobType[] = [