change(ui): remove indexes from msgs

This commit is contained in:
nick-delirium 2023-04-24 15:25:50 +02:00 committed by Delirium
parent 44d550ca3e
commit 01218f4f88
3 changed files with 8 additions and 15 deletions

View file

@ -217,13 +217,14 @@ export default class MessageManager {
async loadMessages(isClickmap: boolean = false) {
this.state.update({ messagesProcessed: false })
this.setMessagesLoading(true)
const noIndexes = this.session.trackerVersion !== '7.0.0'
// TODO: reusable decryptor instance
const createNewParser = (shouldDecrypt = true, file?: string) => {
const decrypt = shouldDecrypt && this.session.fileKey
? (b: Uint8Array) => decryptSessionBytes(b, this.session.fileKey)
: (b: Uint8Array) => Promise.resolve(b)
// Each time called - new fileReader created
const fileReader = new MFileReader(new Uint8Array(), this.sessionStart)
const fileReader = new MFileReader(new Uint8Array(), this.sessionStart, noIndexes)
return (b: Uint8Array) => decrypt(b).then(b => {
fileReader.append(b)
const msgs: Array<Message> = []
@ -231,16 +232,11 @@ export default class MessageManager {
msgs.push(msg)
}
const sorted = msgs.sort((m1, m2) => {
// @ts-ignore
if (!m1.time || !m2.time || m1.time === m2.time) return m1._index - m2._index
return m1.time - m2.time
})
let indx = sorted[0]._index
let outOfOrderCounter = 0
sorted.forEach(msg => {
if (indx > msg._index) outOfOrderCounter++
else indx = msg._index
this.distributeMessage(msg)
})

View file

@ -12,7 +12,7 @@ export default class MFileReader extends RawMessageReader {
private pLastMessageID: number = 0
private currentTime: number
public error: boolean = false
constructor(data: Uint8Array, private startTime?: number, private logger=console) {
constructor(data: Uint8Array, private startTime?: number, private noIndexes?: boolean, private logger= console) {
super(data)
}
@ -49,19 +49,19 @@ export default class MFileReader extends RawMessageReader {
}
}
readNext(): Message & { _index: number } | null {
readNext(): Message & { _index?: number } | null {
if (this.error || !this.hasNextByte()) {
return null
}
while (this.needSkipMessage()) {
while (!this.noIndexes && this.needSkipMessage()) {
const skippedMessage = this.readRawMessage()
if (!skippedMessage) {
return null
}
Logger.group("Openreplay: Skipping messages ", skippedMessage)
}
this.pLastMessageID = this.p
this.pLastMessageID = this.noIndexes ? 0 : this.p
const rMsg = this.readRawMessage()
if (!rMsg) {
@ -76,10 +76,10 @@ export default class MFileReader extends RawMessageReader {
return this.readNext()
}
const index = this.getLastMessageID()
const index = this.noIndexes ? 0 : this.getLastMessageID()
const msg = Object.assign(rewriteMessage(rMsg), {
time: this.currentTime,
_index: index,
_index: this.noIndexes ? undefined : index,
})
return msg

View file

@ -7,7 +7,6 @@ const SIZE_BYTES = 3
const MAX_M_SIZE = (1 << (SIZE_BYTES * 8)) - 1
export default class BatchWriter {
private nextIndex = 0
private beaconSize = 2 * 1e5 // Default 200kB
private encoder = new MessageEncoder(this.beaconSize)
private strDict = new StringDictionary()
@ -47,7 +46,6 @@ export default class BatchWriter {
Messages.Type.BatchMetadata,
1,
this.pageNo,
this.nextIndex,
this.timestamp,
this.url,
]
@ -75,7 +73,6 @@ export default class BatchWriter {
e.checkpoint()
this.isEmpty = this.isEmpty && message[0] === Messages.Type.Timestamp
this.nextIndex++
}
// app.debug.log
return wasWritten