diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-03-27 12:23:14 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-03-28 11:03:31 -0400 |
| commit | 045ff5d2c0037fe0770d619b9f7a21d79a9b668d (patch) | |
| tree | 6adbac5067e821b5ca2f698a9292d71a4f47f5d3 | |
| parent | clear subscriptions when connection closes (diff) | |
| download | sharkey-045ff5d2c0037fe0770d619b9f7a21d79a9b668d.tar.gz sharkey-045ff5d2c0037fe0770d619b9f7a21d79a9b668d.tar.bz2 sharkey-045ff5d2c0037fe0770d619b9f7a21d79a9b668d.zip | |
make sure that note subscriptions can't stay above limit
| -rw-r--r-- | packages/backend/src/server/api/stream/Connection.ts | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts index 691ce54feb..96b968d890 100644 --- a/packages/backend/src/server/api/stream/Connection.ts +++ b/packages/backend/src/server/api/stream/Connection.ts @@ -202,10 +202,11 @@ export default class Connection { if (!payload.id || typeof payload.id !== 'string') return; const current = this.subscribingNotes.get(payload.id) ?? 0; + const updated = current + 1; + this.subscribingNotes.set(payload.id, updated); // Limit the number of distinct notes that can be subscribed to. - // If current is-zero, then this is a new note and we need to check the limit - if (current === 0 && this.subscribingNotes.size >= MAX_SUBSCRIPTIONS_PER_CONNECTION) { + while (this.subscribingNotes.size > MAX_SUBSCRIPTIONS_PER_CONNECTION) { // Map maintains insertion order, so first key is always the oldest // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const oldestKey = this.subscribingNotes.keys().next().value!; @@ -214,9 +215,6 @@ export default class Connection { this.subscriber.off(`noteStream:${oldestKey}`, this.onNoteStreamMessage); } - const updated = current + 1; - this.subscribingNotes.set(payload.id, updated); - if (updated === 1) { this.subscriber.on(`noteStream:${payload.id}`, this.onNoteStreamMessage); } |