mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-05-16 07:09:28 +00:00
fix: buffer optimisation, backwards compatible senderId
This commit is contained in:
parent
13ed84bd6f
commit
a759ad2e2b
@ -18,4 +18,10 @@ export {
|
|||||||
type MessageId
|
type MessageId
|
||||||
} from "./message_channel/index.js";
|
} 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 };
|
export { BloomFilter };
|
||||||
|
|||||||
@ -212,21 +212,26 @@ export class IncomingRepairBuffer {
|
|||||||
* Removes and returns ready entries
|
* Removes and returns ready entries
|
||||||
*/
|
*/
|
||||||
public getReady(currentTime: number): HistoryEntry[] {
|
public getReady(currentTime: number): HistoryEntry[] {
|
||||||
const ready: HistoryEntry[] = [];
|
// Find cutoff point - first item with tResp > currentTime
|
||||||
const remaining: IncomingBufferEntry[] = [];
|
// Since array is sorted, all items before this are ready
|
||||||
|
let cutoff = 0;
|
||||||
for (const item of this.items) {
|
for (let i = 0; i < this.items.length; i++) {
|
||||||
if (item.tResp <= currentTime) {
|
if (this.items[i].tResp > currentTime) {
|
||||||
ready.push(item.entry);
|
cutoff = i;
|
||||||
log.info(`Repair for ${item.entry.messageId} is ready to be sent`);
|
break;
|
||||||
} else {
|
|
||||||
// Since array is sorted, all remaining entries are not ready
|
|
||||||
remaining.push(item);
|
|
||||||
}
|
}
|
||||||
|
// If we reach the end, all items are ready
|
||||||
|
cutoff = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep only non-ready entries
|
// Extract ready items and log them
|
||||||
this.items = remaining;
|
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;
|
return ready;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user