|
@@ -1,5 +1,6 @@
|
|
import { EntityManager } from 'typeorm'
|
|
import { EntityManager } from 'typeorm'
|
|
import { config, ConfigVariable } from './config'
|
|
import { config, ConfigVariable } from './config'
|
|
|
|
+import { getEm } from '../server-extension/orm'
|
|
|
|
|
|
// constant used to parse seconds from creation
|
|
// constant used to parse seconds from creation
|
|
export const NEWNESS_SECONDS_DIVIDER = 60 * 60 * 24
|
|
export const NEWNESS_SECONDS_DIVIDER = 60 * 60 * 24
|
|
@@ -7,6 +8,17 @@ export const NEWNESS_SECONDS_DIVIDER = 60 * 60 * 24
|
|
export class VideoRelevanceManager {
|
|
export class VideoRelevanceManager {
|
|
private videosToUpdate: Set<string> = new Set()
|
|
private videosToUpdate: Set<string> = new Set()
|
|
|
|
|
|
|
|
+ init(intervalMs: number): void {
|
|
|
|
+ this.updateLoop(intervalMs)
|
|
|
|
+ .then(() => {
|
|
|
|
+ /* Do nothing */
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.error(err)
|
|
|
|
+ process.exit(-1)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
scheduleRecalcForVideo(id: string | null | undefined) {
|
|
scheduleRecalcForVideo(id: string | null | undefined) {
|
|
id && this.videosToUpdate.add(id)
|
|
id && this.videosToUpdate.add(id)
|
|
}
|
|
}
|
|
@@ -39,4 +51,12 @@ export class VideoRelevanceManager {
|
|
this.videosToUpdate.clear()
|
|
this.videosToUpdate.clear()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private async updateLoop(intervalMs: number): Promise<void> {
|
|
|
|
+ const em = await getEm()
|
|
|
|
+ while (true) {
|
|
|
|
+ await this.updateVideoRelevanceValue(em, true)
|
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, intervalMs))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|