mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Improve viewer counter
More precise, avoid weird decrease, reuse an id to federate viewers
This commit is contained in:
parent
dfbcefc20d
commit
ac907dc7c1
17 changed files with 235 additions and 156 deletions
|
@ -43,7 +43,7 @@ async function runCommand (req: express.Request, res: express.Response) {
|
|||
const processors: { [id in SendDebugCommand['command']]: () => Promise<any> } = {
|
||||
'remove-dandling-resumable-uploads': () => RemoveDanglingResumableUploadsScheduler.Instance.execute(),
|
||||
'process-video-views-buffer': () => VideoViewsBufferScheduler.Instance.execute(),
|
||||
'process-video-viewers': () => VideoViewsManager.Instance.processViewers()
|
||||
'process-video-viewers': () => VideoViewsManager.Instance.processViewerStats()
|
||||
}
|
||||
|
||||
await processors[body.command]()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import express from 'express'
|
||||
import { sendView } from '@server/lib/activitypub/send/send-view'
|
||||
import { Hooks } from '@server/lib/plugins/hooks'
|
||||
import { VideoViewsManager } from '@server/lib/views/video-views-manager'
|
||||
import { getServerActor } from '@server/models/application/application'
|
||||
import { MVideoId } from '@server/types/models'
|
||||
import { HttpStatusCode, VideoView } from '@shared/models'
|
||||
import { asyncMiddleware, methodsValidator, openapiOperationDoc, optionalAuthenticate, videoViewValidator } from '../../../middlewares'
|
||||
|
@ -33,7 +31,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
const body = req.body as VideoView
|
||||
|
||||
const ip = req.ip
|
||||
const { successView, successViewer } = await VideoViewsManager.Instance.processLocalView({
|
||||
const { successView } = await VideoViewsManager.Instance.processLocalView({
|
||||
video,
|
||||
ip,
|
||||
currentTime: body.currentTime,
|
||||
|
@ -41,15 +39,9 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
})
|
||||
|
||||
if (successView) {
|
||||
await sendView({ byActor: await getServerActor(), video, type: 'view' })
|
||||
|
||||
Hooks.runAction('action:api.video.viewed', { video: video, ip, req, res })
|
||||
}
|
||||
|
||||
if (successViewer) {
|
||||
await sendView({ byActor: await getServerActor(), video, type: 'viewer' })
|
||||
}
|
||||
|
||||
await updateUserHistoryIfNeeded(body, video, res)
|
||||
|
||||
return res.status(HttpStatusCode.NO_CONTENT_204).end()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue