feat(tracker):reset batchSize to initial after sending a big message

This commit is contained in:
Alex Kaminskii 2022-12-27 10:28:27 +01:00
parent fcee35ee3e
commit 0fe5d3c8d3
3 changed files with 19 additions and 13 deletions

View file

@ -36,7 +36,7 @@ export default class BatchWriter {
}
private prepare(): void {
if (!this.encoder.isEmpty()) {
if (!this.encoder.isEmpty) {
return
}
@ -94,19 +94,20 @@ export default class BatchWriter {
if (this.writeWithSize(message)) {
return
}
// buffer overflow, send already written data first then try again
this.finaliseBatch()
while (!this.writeWithSize(message)) {
if (this.beaconSize === this.beaconSizeLimit) {
console.warn('OpenReplay: beacon size overflow. Skipping large message.', message, this)
this.encoder.reset()
this.prepare()
return
}
// MBTODO: tempWriter for one message?
this.beaconSize = Math.min(this.beaconSize * 2, this.beaconSizeLimit)
this.encoder = new MessageEncoder(this.beaconSize)
this.prepare()
if (this.writeWithSize(message)) {
return
}
// buffer is too small. Create one with maximal capacity
this.encoder = new MessageEncoder(this.beaconSizeLimit)
this.prepare()
if (!this.writeWithSize(message)) {
console.warn('OpenReplay: beacon size overflow. Skipping large message.', message, this)
}
// reset encoder to normal size
this.encoder = new MessageEncoder(this.beaconSize)
this.prepare()
}
finaliseBatch() {

View file

@ -66,7 +66,7 @@ export default class PrimitiveEncoder {
checkpoint() {
this.checkpointOffset = this.offset
}
isEmpty(): boolean {
get isEmpty(): boolean {
return this.offset === 0
}
skip(n: number): boolean {

View file

@ -1,3 +1,8 @@
// Do strong type WebWorker as soon as it is possible:
// https://github.com/microsoft/TypeScript/issues/14877
// At the moment "webworker" lib conflicts with jest-environment-jsdom that uses "dom" lib
//
import type Message from '../common/messages.gen.js'
import { Type as MType } from '../common/messages.gen.js'
import { ToWorkerData, FromWorkerData } from '../common/interaction.js'