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 nick-delirium
parent ee46413b13
commit 23514d4b3f
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0

View file

@ -1636,7 +1636,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)
}
})
})
}