Tweak duplicate handling in repository
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
"dependencies": {
|
||||
"@welshman/lib": "0.0.11",
|
||||
"@welshman/net": "0.0.14",
|
||||
"@welshman/util": "0.0.17",
|
||||
"@welshman/util": "0.0.18",
|
||||
"nostr-tools": "^2.7.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@
|
||||
"typescript": "~5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@welshman/util": "0.0.17"
|
||||
"@welshman/util": "0.0.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@welshman/lib": "0.0.11",
|
||||
"@welshman/util": "0.0.17",
|
||||
"@welshman/util": "0.0.18",
|
||||
"isomorphic-ws": "^5.0.0",
|
||||
"ws": "^8.16.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/util",
|
||||
"version": "0.0.17",
|
||||
"version": "0.0.18",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "A collection of nostr-related utilities.",
|
||||
|
||||
@@ -136,21 +136,21 @@ export class Repository extends Emitter {
|
||||
throw new Error("Invalid event published to Repository", event)
|
||||
}
|
||||
|
||||
const address = getAddress(event)
|
||||
const duplicate = (
|
||||
this.eventsById.get(event.id) ||
|
||||
this.eventsByAddress.get(address)
|
||||
)
|
||||
|
||||
// If our duplicate is newer than the event we're adding, we're done
|
||||
if (duplicate && duplicate.created_at >= event.created_at) {
|
||||
this.deletes.set(event.id, duplicate.created_at)
|
||||
|
||||
// If we've already seen this event, we're done
|
||||
if (this.eventsById.get(event.id)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Delete our duplicate
|
||||
const address = getAddress(event)
|
||||
const duplicate = this.eventsByAddress.get(address)
|
||||
|
||||
if (duplicate) {
|
||||
// If our event is older than the duplicate, we're done
|
||||
if (event.created_at <= duplicate.created_at) {
|
||||
return
|
||||
}
|
||||
|
||||
// If our event is newer than what it's replacing, delete the old version
|
||||
this.deletes.set(duplicate.id, event.created_at)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user