- private async updateLiveViews () {
- if (!this.isRunning()) return
-
- if (!isTestInstance()) logger.info('Updating live video views.', lTags())
-
- for (const videoId of this.watchersPerVideo.keys()) {
- const notBefore = new Date().getTime() - VIEW_LIFETIME.LIVE
-
- const watchers = this.watchersPerVideo.get(videoId)
-
- const numWatchers = watchers.length
-
- const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
- video.views = numWatchers
- await video.save()
-
- await federateVideoIfNeeded(video, false)
-
- PeerTubeSocket.Instance.sendVideoViewsUpdate(video)
-
- // Only keep not expired watchers
- const newWatchers = watchers.filter(w => w > notBefore)
- this.watchersPerVideo.set(videoId, newWatchers)
-
- logger.debug('New live video views for %s is %d.', video.url, numWatchers, lTags())
- }
- }
-