From 48b17653ff560a2d919707e1f3ecc4577151fc5d Mon Sep 17 00:00:00 2001 From: Gitlab staging reset job Date: Tue, 4 Jan 2022 16:29:14 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Decrease=20BoundedBuff?= =?UTF-8?q?er=20limitation=20to=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/tools/boundedBuffer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/tools/boundedBuffer.ts b/packages/core/src/tools/boundedBuffer.ts index bdcdabfba6..6d68a79123 100644 --- a/packages/core/src/tools/boundedBuffer.ts +++ b/packages/core/src/tools/boundedBuffer.ts @@ -1,4 +1,4 @@ -const DEFAULT_LIMIT = 10_000 +const DEFAULT_LIMIT = 500 export class BoundedBuffer { private buffer: Array<() => void> = [] From d386406df626ae54e9f86aebdad56e58d8558586 Mon Sep 17 00:00:00 2001 From: Gitlab staging reset job Date: Tue, 4 Jan 2022 16:39:47 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/tools/boundedBuffer.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/core/src/tools/boundedBuffer.spec.ts b/packages/core/src/tools/boundedBuffer.spec.ts index cd132c0c0d..a14f8683c3 100644 --- a/packages/core/src/tools/boundedBuffer.spec.ts +++ b/packages/core/src/tools/boundedBuffer.spec.ts @@ -26,4 +26,17 @@ describe('BoundedBuffer', () => { buffered.drain() expect(spy.calls.count()).toEqual(5) }) + + it('store at most 500 callbacks by default', () => { + const spy = jasmine.createSpy<() => void>() + const buffered = new BoundedBuffer() + const limit = 500 + + for (let i = 0; i < limit + 1; i += 1) { + buffered.add(spy) + } + + buffered.drain() + expect(spy.calls.count()).toEqual(limit) + }) }) From 266f98e8e6777d63add298ef885ba2a168245624 Mon Sep 17 00:00:00 2001 From: Gitlab staging reset job Date: Wed, 5 Jan 2022 14:49:57 +0100 Subject: [PATCH 3/3] Remove constructor param --- packages/core/src/tools/boundedBuffer.spec.ts | 14 +------------- packages/core/src/tools/boundedBuffer.ts | 6 ++---- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/core/src/tools/boundedBuffer.spec.ts b/packages/core/src/tools/boundedBuffer.spec.ts index a14f8683c3..31accb164b 100644 --- a/packages/core/src/tools/boundedBuffer.spec.ts +++ b/packages/core/src/tools/boundedBuffer.spec.ts @@ -15,19 +15,7 @@ describe('BoundedBuffer', () => { expect(spy.calls.count()).toBe(1) }) - it('store only the N last callbacks', () => { - const spy = jasmine.createSpy<() => void>() - const buffered = new BoundedBuffer(5) - - for (let i = 0; i < 10; i += 1) { - buffered.add(spy) - } - - buffered.drain() - expect(spy.calls.count()).toEqual(5) - }) - - it('store at most 500 callbacks by default', () => { + it('store at most 500 callbacks', () => { const spy = jasmine.createSpy<() => void>() const buffered = new BoundedBuffer() const limit = 500 diff --git a/packages/core/src/tools/boundedBuffer.ts b/packages/core/src/tools/boundedBuffer.ts index 6d68a79123..60a6212a72 100644 --- a/packages/core/src/tools/boundedBuffer.ts +++ b/packages/core/src/tools/boundedBuffer.ts @@ -1,13 +1,11 @@ -const DEFAULT_LIMIT = 500 +const BUFFER_LIMIT = 500 export class BoundedBuffer { private buffer: Array<() => void> = [] - constructor(private limit: number = DEFAULT_LIMIT) {} - add(callback: () => void) { const length = this.buffer.push(callback) - if (length > this.limit) { + if (length > BUFFER_LIMIT) { this.buffer.splice(0, 1) } }