mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Fix follows health cache
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user