Fix repository delte notification and CLOSE buffering

This commit is contained in:
Jon Staab
2024-06-03 12:27:53 -07:00
parent 35eccf7467
commit d4cecd5e50
4 changed files with 29 additions and 5 deletions
+4
View File
@@ -63,3 +63,7 @@ export function cached<T, V, Args extends any[]>({
return get
}
export function simpleCache<V, Args extends any[]>(getValue: (args: Args) => V) {
return cached({maxSize: 10**10, getKey: xs => xs.join(':'), getValue})
}
+18 -4
View File
@@ -311,11 +311,25 @@ export const batch = <T>(t: number, f: (xs: T[]) => void) => {
}
}
export const addToMapKey = <K, T>(m: Map<K, Set<T>>, k: K, v: T) => {
const a = m.get(k) || new Set<T>()
export const addToKey = <T>(m: Record<string, Set<T>>, k: string, v: T) => {
const s = m[k] || new Set<T>()
a.add(v)
m.set(k, a)
s.add(v)
m[k] = s
}
export const pushToKey = <T>(m: Record<string, T[]>, k: string, v: T) => {
const a = m[k] || []
a.push(v)
m[k] = a
}
export const addToMapKey = <K, T>(m: Map<K, Set<T>>, k: K, v: T) => {
const s = m.get(k) || new Set<T>()
s.add(v)
m.set(k, s)
}
export const pushToMapKey = <K, T>(m: Map<K, T[]>, k: K, v: T) => {
+6 -1
View File
@@ -30,10 +30,15 @@ export class Connection extends Emitter {
const [verb, ...extra] = asMessage(message)
if (['AUTH', 'CLOSE'].includes(verb)) {
if (verb === 'AUTH') {
return false
}
// Only close reqs that have been sent
if (verb === 'CLOSE') {
return !this.meta.pendingRequests.has(extra[0])
}
// Allow relay requests through
if (verb === 'EVENT' && extra[0].kind === 28934) {
return false
+1
View File
@@ -162,6 +162,7 @@ export class Repository extends Emitter {
// Delete our duplicate first
if (duplicate) {
this.notifyDelete(duplicate)
this.eventsById.delete(duplicate.id)
if (isReplaceable(duplicate)) {