aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/files-cache
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/files-cache')
-rw-r--r--server/lib/files-cache/actor-follow-score-cache.ts75
-rw-r--r--server/lib/files-cache/index.ts2
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 @@
1import { ACTOR_FOLLOW_SCORE } from '../../initializers/constants'
2import { 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
6class 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
73export {
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 @@
1export * from './actor-follow-score-cache'
2export * from './videos-preview-cache' 1export * from './videos-preview-cache'
3export * from './videos-caption-cache' 2export * from './videos-caption-cache'
3export * from './videos-torrent-cache'