1 import { isTestInstance } from '../../helpers/core-utils'
2 import { logger } from '../../helpers/logger'
3 import { ActorFollowModel } from '../../models/activitypub/actor-follow'
4 import { AbstractScheduler } from './abstract-scheduler'
5 import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
6 import { ActorFollowScoreCache } from '../files-cache'
8 export class ActorFollowScheduler extends AbstractScheduler {
10 private static instance: AbstractScheduler
12 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.actorFollowScores
14 private constructor () {
18 protected async internalExecute () {
19 await this.processPendingScores()
21 await this.removeBadActorFollows()
24 private async processPendingScores () {
25 const pendingScores = ActorFollowScoreCache.Instance.getPendingFollowsScoreCopy()
27 ActorFollowScoreCache.Instance.clearPendingFollowsScore()
29 for (const inbox of Object.keys(pendingScores)) {
30 await ActorFollowModel.updateFollowScore(inbox, pendingScores[inbox])
34 private async removeBadActorFollows () {
35 if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).')
38 await ActorFollowModel.removeBadActorFollows()
40 logger.error('Error in bad actor follows scheduler.', { err })
44 static get Instance () {
45 return this.instance || (this.instance = new this())