Fix repository delte notification and CLOSE buffering
This commit is contained in:
@@ -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
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user