Track deletes of duplicates even if they never are added to the repo. Uniqify filters when performing a union
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import {Event} from 'nostr-tools'
|
import {Event} from 'nostr-tools'
|
||||||
import {matchFilter as nostrToolsMatchFilter} 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 type {HashedEvent, TrustedEvent} from './Events'
|
||||||
import {isReplaceableKind} from './Kinds'
|
import {isReplaceableKind} from './Kinds'
|
||||||
import {Address, getAddress} from './Address'
|
import {Address, getAddress} from './Address'
|
||||||
@@ -79,7 +79,8 @@ export const calculateFilterGroup = ({since, until, limit, search, ...filter}: F
|
|||||||
export const unionFilters = (filters: Filter[]) => {
|
export const unionFilters = (filters: Filter[]) => {
|
||||||
const result = []
|
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> = {}
|
const newFilter: Record<string, any> = {}
|
||||||
|
|
||||||
for (const k of Object.keys(group[0])) {
|
for (const k of Object.keys(group[0])) {
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ export class Repository extends Emitter {
|
|||||||
|
|
||||||
// If our duplicate is newer than the event we're adding, we're done
|
// If our duplicate is newer than the event we're adding, we're done
|
||||||
if (duplicate && duplicate.created_at >= event.created_at) {
|
if (duplicate && duplicate.created_at >= event.created_at) {
|
||||||
|
this.deletes.set(event.id, duplicate.created_at)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user