fix: Service worker precache delete
fix: pubkey in profile metadata breaks cache refresh fix: non-specific queries not sent to any relays sometimes fix: sub-query trace not sending "CLOSE"
This commit is contained in:
parent
988416f353
commit
f684658183
@ -41,10 +41,10 @@ export function mapEventToProfile(ev: RawEvent) {
|
||||
try {
|
||||
const data: UserMetadata = JSON.parse(ev.content);
|
||||
return {
|
||||
...data,
|
||||
pubkey: ev.pubkey,
|
||||
npub: hexToBech32("npub", ev.pubkey),
|
||||
created: ev.created_at,
|
||||
...data,
|
||||
loaded: unixNowMs(),
|
||||
} as MetadataCache;
|
||||
} catch (e) {
|
||||
|
@ -13,6 +13,7 @@ class QueryTrace {
|
||||
readonly relay: string;
|
||||
readonly connId: string;
|
||||
readonly start: number;
|
||||
readonly leaveOpen: boolean;
|
||||
sent?: number;
|
||||
eose?: number;
|
||||
close?: number;
|
||||
@ -21,11 +22,19 @@ class QueryTrace {
|
||||
readonly #fnProgress: () => void;
|
||||
readonly #log = debug("QueryTrace");
|
||||
|
||||
constructor(sub: string, relay: string, connId: string, fnClose: (id: string) => void, fnProgress: () => void) {
|
||||
constructor(
|
||||
sub: string,
|
||||
relay: string,
|
||||
connId: string,
|
||||
leaveOpen: boolean,
|
||||
fnClose: (id: string) => void,
|
||||
fnProgress: () => void
|
||||
) {
|
||||
this.id = uuid();
|
||||
this.subId = sub;
|
||||
this.relay = relay;
|
||||
this.connId = connId;
|
||||
this.leaveOpen = leaveOpen;
|
||||
this.start = unixNowMs();
|
||||
this.#fnClose = fnClose;
|
||||
this.#fnProgress = fnProgress;
|
||||
@ -39,6 +48,9 @@ class QueryTrace {
|
||||
gotEose() {
|
||||
this.eose = unixNowMs();
|
||||
this.#fnProgress();
|
||||
if (!this.leaveOpen) {
|
||||
this.sendClose();
|
||||
}
|
||||
//this.#log("[EOSE] %s %s", this.subId, this.relay);
|
||||
}
|
||||
|
||||
@ -46,6 +58,7 @@ class QueryTrace {
|
||||
this.eose = unixNowMs();
|
||||
this.#wasForceClosed = true;
|
||||
this.#fnProgress();
|
||||
this.sendClose();
|
||||
//this.#log("[F-EOSE] %s %s", this.subId, this.relay);
|
||||
}
|
||||
|
||||
@ -199,11 +212,6 @@ export class Query implements QueryBase {
|
||||
eose(sub: string, conn: Readonly<Connection>) {
|
||||
const qt = this.#tracing.find(a => a.subId === sub && a.connId === conn.Id);
|
||||
qt?.gotEose();
|
||||
if (sub === this.id) {
|
||||
if (!this.leaveOpen) {
|
||||
qt?.sendClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,6 +270,7 @@ export class Query implements QueryBase {
|
||||
q.id,
|
||||
c.Address,
|
||||
c.Id,
|
||||
this.leaveOpen,
|
||||
x => c.CloseReq(x),
|
||||
() => this.#onProgress()
|
||||
);
|
||||
|
@ -202,7 +202,7 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> {
|
||||
filters: sf.filters,
|
||||
relays: sf.relay ? [sf.relay] : undefined,
|
||||
} as QueryBase;
|
||||
this.SendSubQuery(q, subQ);
|
||||
this.SendQuery(q, subQ, (q, s, c) => q.sendSubQueryToRelay(c, s));
|
||||
}
|
||||
q.filters = filters;
|
||||
this.notifyChange();
|
||||
@ -234,10 +234,10 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> {
|
||||
filters: sf.filters,
|
||||
relays: sf.relay ? [sf.relay] : undefined,
|
||||
} as QueryBase;
|
||||
this.SendSubQuery(q, subQ);
|
||||
this.SendQuery(q, subQ, (q, s, c) => q.sendSubQueryToRelay(c, s));
|
||||
}
|
||||
} else {
|
||||
this.SendQuery(q);
|
||||
this.SendQuery(q, q, (q, s, c) => q.sendToRelay(c));
|
||||
}
|
||||
this.notifyChange();
|
||||
return store;
|
||||
@ -250,16 +250,16 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> {
|
||||
}
|
||||
}
|
||||
|
||||
async SendQuery(q: Query) {
|
||||
async SendQuery(q: Query, qSend: QueryBase, qSender: (q: Query, qSend: QueryBase, c: Connection) => void) {
|
||||
if (q.relays && q.relays.length > 0) {
|
||||
for (const r of q.relays) {
|
||||
const s = this.Sockets.get(r);
|
||||
if (s) {
|
||||
q.sendToRelay(s);
|
||||
qSender(q, qSend, s);
|
||||
} else {
|
||||
const nc = await this.ConnectEphemeralRelay(r);
|
||||
if (nc) {
|
||||
q.sendToRelay(nc);
|
||||
qSender(q, qSend, nc);
|
||||
} else {
|
||||
console.warn("Failed to connect to new relay for:", r, q);
|
||||
}
|
||||
@ -268,31 +268,7 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> {
|
||||
} else {
|
||||
for (const [, s] of this.Sockets) {
|
||||
if (!s.Ephemeral) {
|
||||
q.sendToRelay(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async SendSubQuery(q: Query, subQ: QueryBase) {
|
||||
if (subQ.relays && subQ.relays.length > 0) {
|
||||
for (const r of subQ.relays) {
|
||||
const s = this.Sockets.get(r);
|
||||
if (s) {
|
||||
q.sendSubQueryToRelay(s, subQ);
|
||||
} else {
|
||||
const nc = await this.ConnectEphemeralRelay(r);
|
||||
if (nc) {
|
||||
q.sendSubQueryToRelay(nc, subQ);
|
||||
} else {
|
||||
console.warn("Failed to connect to new relay for:", r, subQ);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const [, s] of this.Sockets) {
|
||||
if (!s.Ephemeral) {
|
||||
q.sendSubQueryToRelay(s, subQ);
|
||||
qSender(q, qSend, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,10 @@ declare var self: ServiceWorkerGlobalScope;
|
||||
|
||||
import { clientsClaim } from "workbox-core";
|
||||
import { ExpirationPlugin } from "workbox-expiration";
|
||||
import { precacheAndRoute } from "workbox-precaching";
|
||||
import { registerRoute } from "workbox-routing";
|
||||
import { StaleWhileRevalidate, CacheFirst } from "workbox-strategies";
|
||||
|
||||
clientsClaim();
|
||||
precacheAndRoute(self.__WB_MANIFEST);
|
||||
|
||||
const staticTypes = ["image", "video", "audio"];
|
||||
registerRoute(
|
||||
|
Loading…
x
Reference in New Issue
Block a user