Tweak duplicate handling in repository
This commit is contained in:
Generated
+4
-4
@@ -3097,7 +3097,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/lib": "0.0.11",
|
"@welshman/lib": "0.0.11",
|
||||||
"@welshman/net": "0.0.14",
|
"@welshman/net": "0.0.14",
|
||||||
"@welshman/util": "0.0.17",
|
"@welshman/util": "0.0.18",
|
||||||
"nostr-tools": "^2.7.0"
|
"nostr-tools": "^2.7.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -3111,7 +3111,7 @@
|
|||||||
"version": "0.0.12",
|
"version": "0.0.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/util": "0.0.17"
|
"@welshman/util": "0.0.18"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gts": "^5.0.1",
|
"gts": "^5.0.1",
|
||||||
@@ -3149,7 +3149,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/lib": "0.0.11",
|
"@welshman/lib": "0.0.11",
|
||||||
"@welshman/util": "0.0.17",
|
"@welshman/util": "0.0.18",
|
||||||
"isomorphic-ws": "^5.0.0",
|
"isomorphic-ws": "^5.0.0",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
},
|
},
|
||||||
@@ -3161,7 +3161,7 @@
|
|||||||
},
|
},
|
||||||
"packages/util": {
|
"packages/util": {
|
||||||
"name": "@welshman/util",
|
"name": "@welshman/util",
|
||||||
"version": "0.0.17",
|
"version": "0.0.18",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/lib": "0.0.11",
|
"@welshman/lib": "0.0.11",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/lib": "0.0.11",
|
"@welshman/lib": "0.0.11",
|
||||||
"@welshman/net": "0.0.14",
|
"@welshman/net": "0.0.14",
|
||||||
"@welshman/util": "0.0.17",
|
"@welshman/util": "0.0.18",
|
||||||
"nostr-tools": "^2.7.0"
|
"nostr-tools": "^2.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,6 @@
|
|||||||
"typescript": "~5.1.6"
|
"typescript": "~5.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/util": "0.0.17"
|
"@welshman/util": "0.0.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welshman/lib": "0.0.11",
|
"@welshman/lib": "0.0.11",
|
||||||
"@welshman/util": "0.0.17",
|
"@welshman/util": "0.0.18",
|
||||||
"isomorphic-ws": "^5.0.0",
|
"isomorphic-ws": "^5.0.0",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/util",
|
"name": "@welshman/util",
|
||||||
"version": "0.0.17",
|
"version": "0.0.18",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of nostr-related utilities.",
|
"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)
|
throw new Error("Invalid event published to Repository", event)
|
||||||
}
|
}
|
||||||
|
|
||||||
const address = getAddress(event)
|
// If we've already seen this event, we're done
|
||||||
const duplicate = (
|
if (this.eventsById.get(event.id)) {
|
||||||
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)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete our duplicate
|
const address = getAddress(event)
|
||||||
|
const duplicate = this.eventsByAddress.get(address)
|
||||||
|
|
||||||
if (duplicate) {
|
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)
|
this.deletes.set(duplicate.id, event.created_at)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user