mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add ability to delete old remote views
This commit is contained in:
parent
7b293f2868
commit
cda03765fe
15 changed files with 237 additions and 26 deletions
33
server/lib/schedulers/remove-old-views-scheduler.ts
Normal file
33
server/lib/schedulers/remove-old-views-scheduler.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { logger } from '../../helpers/logger'
|
||||
import { AbstractScheduler } from './abstract-scheduler'
|
||||
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
|
||||
import { UserVideoHistoryModel } from '../../models/account/user-video-history'
|
||||
import { CONFIG } from '../../initializers/config'
|
||||
import { isTestInstance } from '../../helpers/core-utils'
|
||||
import { VideoViewModel } from '../../models/video/video-views'
|
||||
|
||||
export class RemoveOldViewsScheduler extends AbstractScheduler {
|
||||
|
||||
private static instance: AbstractScheduler
|
||||
|
||||
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews
|
||||
|
||||
private constructor () {
|
||||
super()
|
||||
}
|
||||
|
||||
protected internalExecute () {
|
||||
if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
|
||||
|
||||
logger.info('Removing old videos views.')
|
||||
|
||||
const now = new Date()
|
||||
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
|
||||
|
||||
return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
|
||||
}
|
||||
|
||||
static get Instance () {
|
||||
return this.instance || (this.instance = new this())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue