Fix follows health cache

This commit is contained in:
Chocobozzz
2026-04-24 15:03:25 +02:00
parent 30c3e09852
commit a817434162
2 changed files with 10 additions and 13 deletions
@@ -197,7 +197,7 @@ function broadcastTo (options: {
// Bad URIs could be slow to respond, prefer to process them in a dedicated queue
for (const uri of uris) {
if (ActorFollowHealthCache.Instance.isBadInbox(uri)) {
if (ActorFollowHealthCache.Instance.isLastBadInbox(uri)) {
unicastUris.push(uri)
} else {
broadcastUris.push(uri)
+9 -12
View File
@@ -1,4 +1,3 @@
import { ACTOR_FOLLOW_SCORE } from '../initializers/constants.js'
import { logger } from '../helpers/logger.js'
// Cache follows scores, instead of writing them too often in database
@@ -6,14 +5,14 @@ import { logger } from '../helpers/logger.js'
export class ActorFollowHealthCache {
private static instance: ActorFollowHealthCache
private pendingFollowsScore: { [url: string]: number } = {}
private readonly pendingBadServer = new Set<number>()
private readonly pendingGoodServer = new Set<number>()
private readonly badInboxes = new Set<string>()
private readonly goodInboxes = new Set<string>()
private readonly lastBatchBadInboxes = new Set<string>()
private constructor () {}
static get Instance () {
@@ -21,7 +20,7 @@ export class ActorFollowHealthCache {
}
updateActorFollowsHealth (goodInboxes: string[], badInboxes: string[]) {
this.badInboxes.clear()
this.lastBatchBadInboxes.clear()
if (goodInboxes.length === 0 && badInboxes.length === 0) return
@@ -33,23 +32,21 @@ export class ActorFollowHealthCache {
)
for (const goodInbox of goodInboxes) {
if (this.pendingFollowsScore[goodInbox] === undefined) this.pendingFollowsScore[goodInbox] = 0
this.pendingFollowsScore[goodInbox] += ACTOR_FOLLOW_SCORE.BONUS
this.goodInboxes.add(goodInbox)
}
for (const badInbox of badInboxes) {
if (this.pendingFollowsScore[badInbox] === undefined) this.pendingFollowsScore[badInbox] = 0
this.pendingFollowsScore[badInbox] += ACTOR_FOLLOW_SCORE.PENALTY
this.badInboxes.add(badInbox)
this.lastBatchBadInboxes.add(badInbox)
}
}
isBadInbox (inboxUrl: string) {
return this.badInboxes.has(inboxUrl)
isLastBadInbox (inboxUrl: string) {
return this.lastBatchBadInboxes.has(inboxUrl)
}
// ---------------------------------------------------------------------------
getBadInboxes () {
return new Set(this.badInboxes)
}