Skip to content

Commit

Permalink
Merge pull request #360 from Microsoft/ConcatError
Browse files Browse the repository at this point in the history
Check if it's safe to call array.concat
  • Loading branch information
Kamil Szostak authored Dec 2, 2016
2 parents f66949a + d637eef commit 3661cb8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions JavaScript/JavaScriptSDK/SendBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,25 @@ module Microsoft.ApplicationInsights {
}

public markAsSent(payload: string[]) {
var sentElements = this.getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY);
sentElements = sentElements.concat(payload);
this._buffer = this.removePayloadsFromBuffer(payload, this._buffer);
this.setBuffer(SessionStorageSendBuffer.BUFFER_KEY, this._buffer);

if (sentElements.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
// We send telemetry normally. If the SENT_BUFFER is too big we don't add new elements
// until we receive a response from the backend and the buffer has free space again (see clearSent method)
_InternalLogging.throwInternalUserActionable(LoggingSeverity.CRITICAL,
new _InternalLogMessage(_InternalMessageId.USRACT_SessionStorageBufferFull,
"Sent buffer reached its maximum size: " + sentElements.length));
var sentElements = this.getBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY);
if (sentElements instanceof Array && payload instanceof Array) {
sentElements = sentElements.concat(payload);

sentElements.length = SessionStorageSendBuffer.MAX_BUFFER_SIZE;
}
if (sentElements.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
// We send telemetry normally. If the SENT_BUFFER is too big we don't add new elements
// until we receive a response from the backend and the buffer has free space again (see clearSent method)
_InternalLogging.throwInternalUserActionable(LoggingSeverity.CRITICAL,
new _InternalLogMessage(_InternalMessageId.USRACT_SessionStorageBufferFull,
"Sent buffer reached its maximum size: " + sentElements.length));

this._buffer = this.removePayloadsFromBuffer(payload, this._buffer);
sentElements.length = SessionStorageSendBuffer.MAX_BUFFER_SIZE;
}

this.setBuffer(SessionStorageSendBuffer.BUFFER_KEY, this._buffer);
this.setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, sentElements);
this.setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, sentElements);
}
}

public clearSent(payload: string[]) {
Expand Down

0 comments on commit 3661cb8

Please sign in to comment.