Skip to content

Commit

Permalink
Don't insert entries that are equally "new" to stored ones
Browse files Browse the repository at this point in the history
Both entries would be valid according to the spec, so we take the one with less computation.
Most likely happens when the entries are identical, which can happen during syncs.
  • Loading branch information
xash committed Nov 12, 2024
1 parent f2a4e8f commit f123bbf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,25 @@ export class Store<
};
}

const otherPayloadLengthIsGreater =
entry.payloadLength < otherEntry.payloadLength;

// If the timestamps and hashes are the same, and the other payload's length is greater, we have a no-op.
if (
otherEntry.timestamp === entry.timestamp &&
payloadDigestOrder === 0 && otherPayloadLengthIsGreater
payloadDigestOrder === 0 &&
entry.payloadLength < otherEntry.payloadLength
) {
this.ingestionMutex.release(acquisitionId);

return {
kind: "no_op",
reason: "obsolete_from_same_subspace",
};
}

// If all three qualities are the same, neither is newer than the other. So we can also have a no-op.
if (
otherEntry.timestamp === entry.timestamp &&
payloadDigestOrder === 0 &&
entry.payloadLength === otherEntry.payloadLength
) {
this.ingestionMutex.release(acquisitionId);

Expand Down

0 comments on commit f123bbf

Please sign in to comment.