mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-02-25 08:13:14 +00:00
fix: buffer optimisation, backwards compatible senderId
This commit is contained in:
parent
13ed84bd6f
commit
a759ad2e2b
@ -18,4 +18,10 @@ export {
|
||||
type MessageId
|
||||
} from "./message_channel/index.js";
|
||||
|
||||
/**
|
||||
* @deprecated Use ParticipantId instead. SenderId has been renamed to ParticipantId
|
||||
* to better reflect that it represents a channel participant, not just a message sender.
|
||||
*/
|
||||
export type SenderId = import("./message_channel/index.js").ParticipantId;
|
||||
|
||||
export { BloomFilter };
|
||||
|
||||
@ -212,21 +212,26 @@ export class IncomingRepairBuffer {
|
||||
* Removes and returns ready entries
|
||||
*/
|
||||
public getReady(currentTime: number): HistoryEntry[] {
|
||||
const ready: HistoryEntry[] = [];
|
||||
const remaining: IncomingBufferEntry[] = [];
|
||||
|
||||
for (const item of this.items) {
|
||||
if (item.tResp <= currentTime) {
|
||||
ready.push(item.entry);
|
||||
log.info(`Repair for ${item.entry.messageId} is ready to be sent`);
|
||||
} else {
|
||||
// Since array is sorted, all remaining entries are not ready
|
||||
remaining.push(item);
|
||||
// Find cutoff point - first item with tResp > currentTime
|
||||
// Since array is sorted, all items before this are ready
|
||||
let cutoff = 0;
|
||||
for (let i = 0; i < this.items.length; i++) {
|
||||
if (this.items[i].tResp > currentTime) {
|
||||
cutoff = i;
|
||||
break;
|
||||
}
|
||||
// If we reach the end, all items are ready
|
||||
cutoff = i + 1;
|
||||
}
|
||||
|
||||
// Keep only non-ready entries
|
||||
this.items = remaining;
|
||||
// Extract ready items and log them
|
||||
const ready = this.items.slice(0, cutoff).map((item) => {
|
||||
log.info(`Repair for ${item.entry.messageId} is ready to be sent`);
|
||||
return item.entry;
|
||||
});
|
||||
|
||||
// Keep only items after cutoff
|
||||
this.items = this.items.slice(cutoff);
|
||||
|
||||
return ready;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user