mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 08:43:09 +00:00
fix: further buffer optimisations
This commit is contained in:
parent
d07298f57a
commit
90f032dd14
@ -93,12 +93,14 @@ export class OutgoingRepairBuffer {
|
||||
|
||||
// Iterate from front of sorted array (earliest T_req first)
|
||||
for (const item of this.items) {
|
||||
// Only return items that are eligible and haven't been requested yet
|
||||
if (
|
||||
item.tReq <= currentTime &&
|
||||
!item.requested &&
|
||||
eligible.length < maxRequests
|
||||
) {
|
||||
// Since array is sorted, once we hit an item with tReq > currentTime,
|
||||
// all remaining items also have tReq > currentTime
|
||||
if (item.tReq > currentTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Only return items that haven't been requested yet
|
||||
if (!item.requested && eligible.length < maxRequests) {
|
||||
eligible.push(item.entry);
|
||||
// Mark as requested so we don't request it again
|
||||
item.requested = true;
|
||||
@ -106,6 +108,11 @@ export class OutgoingRepairBuffer {
|
||||
`Repair request for ${item.entry.messageId} is eligible and marked as requested`
|
||||
);
|
||||
}
|
||||
|
||||
// If we've found enough eligible items, exit early
|
||||
if (eligible.length >= maxRequests) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return eligible;
|
||||
|
||||
@ -172,10 +172,22 @@ export class RepairManager {
|
||||
*/
|
||||
public onMessageReceived(messageId: string): void {
|
||||
// Remove from both buffers as we no longer need to request or respond
|
||||
this.outgoingBuffer.remove(messageId);
|
||||
this.incomingBuffer.remove(messageId);
|
||||
const wasInOutgoing = this.outgoingBuffer.has(messageId);
|
||||
const wasInIncoming = this.incomingBuffer.has(messageId);
|
||||
|
||||
log.info(`Removed ${messageId} from repair buffers after receipt`);
|
||||
if (wasInOutgoing) {
|
||||
this.outgoingBuffer.remove(messageId);
|
||||
log.info(
|
||||
`Removed ${messageId} from outgoing repair buffer after receipt`
|
||||
);
|
||||
}
|
||||
|
||||
if (wasInIncoming) {
|
||||
this.incomingBuffer.remove(messageId);
|
||||
log.info(
|
||||
`Removed ${messageId} from incoming repair buffer after receipt`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user