Enable viewers protocol v2
This commit is contained in:
parent
6aa1ac1db4
commit
fcd71e14a4
5 changed files with 13 additions and 48 deletions
|
@ -64,7 +64,3 @@ export function isProdInstance () {
|
|||
export function getAppNumber () {
|
||||
return process.env.NODE_APP_INSTANCE || ''
|
||||
}
|
||||
|
||||
export function isUsingViewersFederationV2 () {
|
||||
return process.env.USE_VIEWERS_FEDERATION_V2 === 'true'
|
||||
}
|
||||
|
|
|
@ -203,33 +203,12 @@ describe('Test video views/viewers counters', function () {
|
|||
})
|
||||
}
|
||||
|
||||
describe('Federation V1', function () {
|
||||
describe('Federation', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await prepareViewsServers({ viewExpiration: '5 seconds', viewersFederationV2: false })
|
||||
})
|
||||
|
||||
describe('Not using session id', function () {
|
||||
runTests({ useSessionId: false })
|
||||
})
|
||||
|
||||
describe('Using session id', function () {
|
||||
runTests({ useSessionId: true })
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Federation V2', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await prepareViewsServers({ viewExpiration: '5 seconds', viewersFederationV2: true })
|
||||
servers = await prepareViewsServers({ viewExpiration: '5 seconds' })
|
||||
})
|
||||
|
||||
describe('Not using session id', function () {
|
||||
|
@ -277,7 +256,7 @@ describe('Test video views/viewers counters', function () {
|
|||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await prepareViewsServers({ viewExpiration: '5 seconds', viewersFederationV2: true, trustViewerSessionId: false });
|
||||
servers = await prepareViewsServers({ viewExpiration: '5 seconds', trustViewerSessionId: false });
|
||||
|
||||
({ uuid: videoUUID } = await servers[0].videos.quickUpload({ name: 'video' }))
|
||||
await waitJobs(servers)
|
||||
|
|
|
@ -31,16 +31,11 @@ async function processViewsBuffer (servers: PeerTubeServer[]) {
|
|||
}
|
||||
|
||||
async function prepareViewsServers (options: {
|
||||
viewersFederationV2?: boolean
|
||||
viewExpiration?: string // default 1 second
|
||||
trustViewerSessionId?: boolean // default true
|
||||
} = {}) {
|
||||
const { viewExpiration = '1 second', trustViewerSessionId = true } = options
|
||||
|
||||
const env = options?.viewersFederationV2 === true
|
||||
? { USE_VIEWERS_FEDERATION_V2: 'true' }
|
||||
: undefined
|
||||
|
||||
const config = {
|
||||
views: {
|
||||
videos: {
|
||||
|
@ -51,7 +46,7 @@ async function prepareViewsServers (options: {
|
|||
}
|
||||
}
|
||||
|
||||
const servers = await createMultipleServers(2, config, { env })
|
||||
const servers = await createMultipleServers(2, config)
|
||||
await setAccessTokensToServers(servers)
|
||||
await setDefaultVideoChannel(servers)
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import { Transaction } from 'sequelize'
|
||||
import { ActivityAudience, ActivityView } from '@peertube/peertube-models'
|
||||
import { VideoViewsManager } from '@server/lib/views/video-views-manager.js'
|
||||
import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models/index.js'
|
||||
import { ActivityAudience, ActivityView } from '@peertube/peertube-models'
|
||||
import { Transaction } from 'sequelize'
|
||||
import { logger } from '../../../helpers/logger.js'
|
||||
import { audiencify, getAudience } from '../audience.js'
|
||||
import { getLocalVideoViewActivityPubUrl } from '../url.js'
|
||||
import { sendVideoRelatedActivity } from './shared/send-utils.js'
|
||||
import { isUsingViewersFederationV2 } from '@peertube/peertube-node-utils'
|
||||
|
||||
async function sendView (options: {
|
||||
byActor: MActorLight
|
||||
|
@ -61,12 +60,10 @@ function buildViewActivity (options: {
|
|||
|
||||
expires: new Date(VideoViewsManager.Instance.buildViewerExpireTime()).toISOString(),
|
||||
|
||||
result: isUsingViewersFederationV2()
|
||||
? {
|
||||
interactionType: 'WatchAction',
|
||||
type: 'InteractionCounter',
|
||||
userInteractionCount: viewersCount
|
||||
}
|
||||
: undefined
|
||||
result: {
|
||||
interactionType: 'WatchAction',
|
||||
type: 'InteractionCounter',
|
||||
userInteractionCount: viewersCount
|
||||
}
|
||||
}, audience)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { isTestOrDevInstance, isUsingViewersFederationV2 } from '@peertube/peertube-node-utils'
|
||||
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
|
||||
import { exists } from '@server/helpers/custom-validators/misc.js'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||
import { VIEW_LIFETIME } from '@server/initializers/constants.js'
|
||||
|
@ -223,7 +223,7 @@ export class VideoViewerCounters {
|
|||
const federationLimit = now - (VIEW_LIFETIME.VIEWER_COUNTER * 0.75)
|
||||
|
||||
if (viewer.lastFederation && viewer.lastFederation > federationLimit) return
|
||||
if (video.remote === false && isUsingViewersFederationV2()) return
|
||||
if (video.remote === false) return
|
||||
|
||||
await sendView({
|
||||
byActor: await getServerActor(),
|
||||
|
@ -236,8 +236,6 @@ export class VideoViewerCounters {
|
|||
}
|
||||
|
||||
private async federateTotalViewers (video: MVideoImmutable) {
|
||||
if (!isUsingViewersFederationV2()) return
|
||||
|
||||
await sendView({
|
||||
byActor: await getServerActor(),
|
||||
video,
|
||||
|
|
Loading…
Add table
Reference in a new issue