aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/live/live-quota-store.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-22 15:52:59 +0200
committerChocobozzz <me@florianbigard.com>2023-05-22 15:52:59 +0200
commit3f0ceab06e5320f62f593c49daa30d963dbc36f9 (patch)
treec041455a11c55617251def4b7b35eff8d530a97a /server/lib/live/live-quota-store.ts
parentfa3da7a623fdb25be52ebff14e066a99ea9fb0cf (diff)
downloadPeerTube-3f0ceab06e5320f62f593c49daa30d963dbc36f9.tar.gz
PeerTube-3f0ceab06e5320f62f593c49daa30d963dbc36f9.tar.zst
PeerTube-3f0ceab06e5320f62f593c49daa30d963dbc36f9.zip
More robust quota check
Avoid concurrency issues with permanent lives
Diffstat (limited to 'server/lib/live/live-quota-store.ts')
-rw-r--r--server/lib/live/live-quota-store.ts14
1 files changed, 7 insertions, 7 deletions
diff --git a/server/lib/live/live-quota-store.ts b/server/lib/live/live-quota-store.ts
index 8ceccde98..44539faaa 100644
--- a/server/lib/live/live-quota-store.ts
+++ b/server/lib/live/live-quota-store.ts
@@ -2,31 +2,31 @@ class LiveQuotaStore {
2 2
3 private static instance: LiveQuotaStore 3 private static instance: LiveQuotaStore
4 4
5 private readonly livesPerUser = new Map<number, { liveId: number, size: number }[]>() 5 private readonly livesPerUser = new Map<number, { sessionId: string, size: number }[]>()
6 6
7 private constructor () { 7 private constructor () {
8 } 8 }
9 9
10 addNewLive (userId: number, liveId: number) { 10 addNewLive (userId: number, sessionId: string) {
11 if (!this.livesPerUser.has(userId)) { 11 if (!this.livesPerUser.has(userId)) {
12 this.livesPerUser.set(userId, []) 12 this.livesPerUser.set(userId, [])
13 } 13 }
14 14
15 const currentUserLive = { liveId, size: 0 } 15 const currentUserLive = { sessionId, size: 0 }
16 const livesOfUser = this.livesPerUser.get(userId) 16 const livesOfUser = this.livesPerUser.get(userId)
17 livesOfUser.push(currentUserLive) 17 livesOfUser.push(currentUserLive)
18 } 18 }
19 19
20 removeLive (userId: number, liveId: number) { 20 removeLive (userId: number, sessionId: string) {
21 const newLivesPerUser = this.livesPerUser.get(userId) 21 const newLivesPerUser = this.livesPerUser.get(userId)
22 .filter(o => o.liveId !== liveId) 22 .filter(o => o.sessionId !== sessionId)
23 23
24 this.livesPerUser.set(userId, newLivesPerUser) 24 this.livesPerUser.set(userId, newLivesPerUser)
25 } 25 }
26 26
27 addQuotaTo (userId: number, liveId: number, size: number) { 27 addQuotaTo (userId: number, sessionId: string, size: number) {
28 const lives = this.livesPerUser.get(userId) 28 const lives = this.livesPerUser.get(userId)
29 const live = lives.find(l => l.liveId === liveId) 29 const live = lives.find(l => l.sessionId === sessionId)
30 30
31 live.size += size 31 live.size += size
32 } 32 }