aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 17:33:36 +0200
committerChocobozzz <me@florianbigard.com>2019-04-12 08:31:06 +0200
commitcda03765fe366f028897e9b02dd4a0a19af3c935 (patch)
tree4d30303d76f8fd171195a51b1f737a0067987d6c /server/lib
parent7b293f28686319242958dff7315cdd8ad74fc15e (diff)
downloadPeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.gz
PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.tar.zst
PeerTube-cda03765fe366f028897e9b02dd4a0a19af3c935.zip
Add ability to delete old remote views
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/schedulers/remove-old-views-scheduler.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/server/lib/schedulers/remove-old-views-scheduler.ts b/server/lib/schedulers/remove-old-views-scheduler.ts
new file mode 100644
index 000000000..39fbb9163
--- /dev/null
+++ b/server/lib/schedulers/remove-old-views-scheduler.ts
@@ -0,0 +1,33 @@
1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler'
3import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
4import { UserVideoHistoryModel } from '../../models/account/user-video-history'
5import { CONFIG } from '../../initializers/config'
6import { isTestInstance } from '../../helpers/core-utils'
7import { VideoViewModel } from '../../models/video/video-views'
8
9export class RemoveOldViewsScheduler extends AbstractScheduler {
10
11 private static instance: AbstractScheduler
12
13 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.removeOldViews
14
15 private constructor () {
16 super()
17 }
18
19 protected internalExecute () {
20 if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE === -1) return
21
22 logger.info('Removing old videos views.')
23
24 const now = new Date()
25 const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
26
27 return VideoViewModel.removeOldRemoteViewsHistory(beforeDate)
28 }
29
30 static get Instance () {
31 return this.instance || (this.instance = new this())
32 }
33}