diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-13 11:47:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-13 11:47:32 +0200 |
commit | 9db437c8155f3563a33e22ed2896072a9f1fbdb0 (patch) | |
tree | 716078fbe1506e0b0d19936f4939e9c530b3b8ab /server/lib/files-cache | |
parent | e81f6ccf989d4573b59ec7b2bf2812fe3e9fb534 (diff) | |
download | PeerTube-9db437c8155f3563a33e22ed2896072a9f1fbdb0.tar.gz PeerTube-9db437c8155f3563a33e22ed2896072a9f1fbdb0.tar.zst PeerTube-9db437c8155f3563a33e22ed2896072a9f1fbdb0.zip |
Process slow followers in unicast job queue
Diffstat (limited to 'server/lib/files-cache')
-rw-r--r-- | server/lib/files-cache/actor-follow-score-cache.ts | 75 | ||||
-rw-r--r-- | server/lib/files-cache/index.ts | 2 |
2 files changed, 1 insertions, 76 deletions
diff --git a/server/lib/files-cache/actor-follow-score-cache.ts b/server/lib/files-cache/actor-follow-score-cache.ts deleted file mode 100644 index 465080e72..000000000 --- a/server/lib/files-cache/actor-follow-score-cache.ts +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | import { ACTOR_FOLLOW_SCORE } from '../../initializers/constants' | ||
2 | import { logger } from '../../helpers/logger' | ||
3 | |||
4 | // Cache follows scores, instead of writing them too often in database | ||
5 | // Keep data in memory, we don't really need Redis here as we don't really care to loose some scores | ||
6 | class ActorFollowScoreCache { | ||
7 | |||
8 | private static instance: ActorFollowScoreCache | ||
9 | private pendingFollowsScore: { [ url: string ]: number } = {} | ||
10 | private pendingBadServer = new Set<number>() | ||
11 | private pendingGoodServer = new Set<number>() | ||
12 | |||
13 | private constructor () {} | ||
14 | |||
15 | static get Instance () { | ||
16 | return this.instance || (this.instance = new this()) | ||
17 | } | ||
18 | |||
19 | updateActorFollowsScore (goodInboxes: string[], badInboxes: string[]) { | ||
20 | if (goodInboxes.length === 0 && badInboxes.length === 0) return | ||
21 | |||
22 | logger.info( | ||
23 | 'Updating %d good actor follows and %d bad actor follows scores in cache.', | ||
24 | goodInboxes.length, badInboxes.length, { badInboxes } | ||
25 | ) | ||
26 | |||
27 | for (const goodInbox of goodInboxes) { | ||
28 | if (this.pendingFollowsScore[goodInbox] === undefined) this.pendingFollowsScore[goodInbox] = 0 | ||
29 | |||
30 | this.pendingFollowsScore[goodInbox] += ACTOR_FOLLOW_SCORE.BONUS | ||
31 | } | ||
32 | |||
33 | for (const badInbox of badInboxes) { | ||
34 | if (this.pendingFollowsScore[badInbox] === undefined) this.pendingFollowsScore[badInbox] = 0 | ||
35 | |||
36 | this.pendingFollowsScore[badInbox] += ACTOR_FOLLOW_SCORE.PENALTY | ||
37 | } | ||
38 | } | ||
39 | |||
40 | addBadServerId (serverId: number) { | ||
41 | this.pendingBadServer.add(serverId) | ||
42 | } | ||
43 | |||
44 | getBadFollowingServerIds () { | ||
45 | return Array.from(this.pendingBadServer) | ||
46 | } | ||
47 | |||
48 | clearBadFollowingServerIds () { | ||
49 | this.pendingBadServer = new Set<number>() | ||
50 | } | ||
51 | |||
52 | addGoodServerId (serverId: number) { | ||
53 | this.pendingGoodServer.add(serverId) | ||
54 | } | ||
55 | |||
56 | getGoodFollowingServerIds () { | ||
57 | return Array.from(this.pendingGoodServer) | ||
58 | } | ||
59 | |||
60 | clearGoodFollowingServerIds () { | ||
61 | this.pendingGoodServer = new Set<number>() | ||
62 | } | ||
63 | |||
64 | getPendingFollowsScore () { | ||
65 | return this.pendingFollowsScore | ||
66 | } | ||
67 | |||
68 | clearPendingFollowsScore () { | ||
69 | this.pendingFollowsScore = {} | ||
70 | } | ||
71 | } | ||
72 | |||
73 | export { | ||
74 | ActorFollowScoreCache | ||
75 | } | ||
diff --git a/server/lib/files-cache/index.ts b/server/lib/files-cache/index.ts index e921d04a7..e5853f7d6 100644 --- a/server/lib/files-cache/index.ts +++ b/server/lib/files-cache/index.ts | |||
@@ -1,3 +1,3 @@ | |||
1 | export * from './actor-follow-score-cache' | ||
2 | export * from './videos-preview-cache' | 1 | export * from './videos-preview-cache' |
3 | export * from './videos-caption-cache' | 2 | export * from './videos-caption-cache' |
3 | export * from './videos-torrent-cache' | ||