fix: buffer optimisation, backwards compatible senderId

This commit is contained in:
jm-clius 2025-10-23 14:55:05 +01:00
parent 13ed84bd6f
commit a759ad2e2b
No known key found for this signature in database
GPG Key ID: 5FCD9D5211B952DA
2 changed files with 23 additions and 12 deletions

View File

@ -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 };

View File

@ -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;
}