Running buffer slicing when browser is idle (#3050)

* Fixed tracker uploadOfflineRecording

* Make FlushBuffer perform slicing when browser is idle

* Use map function to cast away proxy objects in flushBuffer
This commit is contained in:
Aspyryan 2025-03-03 17:01:35 +01:00 committed by GitHub
parent 6b26f85d6e
commit 51496ae5e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1635,7 +1635,7 @@ export default class App {
}
flushBuffer = async (buffer: Message[]) => {
return new Promise((res) => {
return new Promise((res, reject) => {
if (buffer.length === 0) {
res(null);
return;
@ -1648,9 +1648,19 @@ export default class App {
endIndex++;
}
const messagesBatch = buffer.splice(0, endIndex);
this.postToWorker(messagesBatch);
res(null);
requestIdleCb(() => {
try {
const messagesBatch = buffer.splice(0, endIndex);
// Cast out the proxy object to a regular array.
this.postToWorker(messagesBatch.map(x => [...x]));
res(null);
} catch (e) {
this._debug('flushBuffer', e);
reject(e);
}
})
})
}