Track deletes of duplicates even if they never are added to the repo. Uniqify filters when performing a union

This commit is contained in:
Jon Staab
2024-06-06 17:40:57 -07:00
parent fc00208fe3
commit 48f0e99a5b
2 changed files with 5 additions and 2 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
import {Event} from 'nostr-tools'
import {matchFilter as nostrToolsMatchFilter} from 'nostr-tools'
import {prop, mapVals, shuffle, avg, hash, groupBy, randomId, uniq} from '@welshman/lib'
import {uniqBy, prop, mapVals, shuffle, avg, hash, groupBy, randomId, uniq} from '@welshman/lib'
import type {HashedEvent, TrustedEvent} from './Events'
import {isReplaceableKind} from './Kinds'
import {Address, getAddress} from './Address'
@@ -79,7 +79,8 @@ export const calculateFilterGroup = ({since, until, limit, search, ...filter}: F
export const unionFilters = (filters: Filter[]) => {
const result = []
for (const group of groupBy(calculateFilterGroup, filters).values()) {
// Group, but also get unique filters by ids because duplicates can come through subscribe
for (const group of groupBy(calculateFilterGroup, uniqBy(getFilterId, filters)).values()) {
const newFilter: Record<string, any> = {}
for (const k of Object.keys(group[0])) {
+2
View File
@@ -140,6 +140,8 @@ export class Repository extends Emitter {
// 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
}