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
|
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) => {
|
export const addToKey = <T>(m: Record<string, Set<T>>, k: string, v: T) => {
|
||||||
const a = m.get(k) || new Set<T>()
|
const s = m[k] || new Set<T>()
|
||||||
|
|
||||||
a.add(v)
|
s.add(v)
|
||||||
m.set(k, a)
|
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) => {
|
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)
|
const [verb, ...extra] = asMessage(message)
|
||||||
|
|
||||||
if (['AUTH', 'CLOSE'].includes(verb)) {
|
if (verb === 'AUTH') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only close reqs that have been sent
|
||||||
|
if (verb === 'CLOSE') {
|
||||||
|
return !this.meta.pendingRequests.has(extra[0])
|
||||||
|
}
|
||||||
|
|
||||||
// Allow relay requests through
|
// Allow relay requests through
|
||||||
if (verb === 'EVENT' && extra[0].kind === 28934) {
|
if (verb === 'EVENT' && extra[0].kind === 28934) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ export class Repository extends Emitter {
|
|||||||
|
|
||||||
// Delete our duplicate first
|
// Delete our duplicate first
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
|
this.notifyDelete(duplicate)
|
||||||
this.eventsById.delete(duplicate.id)
|
this.eventsById.delete(duplicate.id)
|
||||||
|
|
||||||
if (isReplaceable(duplicate)) {
|
if (isReplaceable(duplicate)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user