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