Revert "perf(profile): implement stale-while-revalidate for lists and messages"

This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-26 13:18:51 -05:00
1 parent b570350412
commit 27b71ba9bb
4 files changed
+106 -163

No files matched your search

+86 -54
View File
@@ -4,13 +4,12 @@ import assert from "node:assert/strict";
import { JSDOM } from "jsdom";
import { nostrClient } from "../js/nostrClientFacade.js";
import { getActiveSigner, setActiveSigner, clearActiveSigner } from "../js/nostr/client.js";
import { getActiveSigner, setActiveSigner } from "../js/nostr/client.js";
import { subscriptions } from "../js/subscriptions.js";
import { setApplication } from "../js/applicationContext.js";
import nostrService from "../js/services/nostrService.js";
import moderationService from "../js/services/moderationService.js";
import { getNostrEventSchema, NOTE_TYPES } from "../js/nostrEventSchemas.js";
import { profileCache } from "../js/state/profileCache.js";
test("loadSubscriptions aggregates relay results when one rejects", async () => {
const SubscriptionsManager = subscriptions.constructor;
@@ -72,8 +71,6 @@ test("loadSubscriptions aggregates relay results when one rejects", async () =>
const decryptCalls = [];
globalThis.window.nostr = {
getPublicKey: async () => "0000000000000000000000000000000000000000000000000000000000000123",
signEvent: async () => ({}),
nip04: {
async decrypt(_pubkey, ciphertext) {
decryptCalls.push(ciphertext);
@@ -86,7 +83,7 @@ test("loadSubscriptions aggregates relay results when one rejects", async () =>
};
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000123");
await manager.loadSubscriptions("user-pubkey-123");
assert.deepEqual(
Array.from(manager.subscribedPubkeys),
@@ -133,9 +130,6 @@ test("loadSubscriptions aggregates relay results when one rejects", async () =>
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
});
@@ -176,7 +170,7 @@ test("loadSubscriptions queries the correct subscription list kind", async () =>
nostrClient.ensureExtensionPermissions = async () => ({ ok: true });
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000002");
await manager.loadSubscriptions("user-pubkey-legacy");
assert.ok(
capturedFilters.length > 0,
@@ -216,9 +210,6 @@ test("loadSubscriptions queries the correct subscription list kind", async () =>
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
});
@@ -235,6 +226,12 @@ test("loadSubscriptions falls back to nip44 when hinted", async () => {
const originalPool = nostrClient.pool;
const originalEnsurePermissions = nostrClient.ensureExtensionPermissions;
const hadWindow = typeof globalThis.window !== "undefined";
if (!hadWindow) {
globalThis.window = {};
}
const originalWindowNostr = globalThis.window.nostr;
const relayUrls = ["wss://relay-nip44.example"];
nostrClient.relays = relayUrls;
nostrClient.writeRelays = relayUrls;
@@ -255,20 +252,23 @@ test("loadSubscriptions falls back to nip44 when hinted", async () => {
nostrClient.ensureExtensionPermissions = async () => ({ ok: true });
const decryptCalls = { nip04: 0, nip44: 0 };
setActiveSigner({
pubkey: "0000000000000000000000000000000000000000000000000000000000000005",
async nip04Decrypt() {
decryptCalls.nip04 += 1;
throw new Error("nip04 unavailable");
globalThis.window.nostr = {
nip04: {
async decrypt() {
decryptCalls.nip04 += 1;
throw new Error("nip04 unavailable");
},
},
async nip44Decrypt(_pubkey, ciphertext) {
decryptCalls.nip44 += 1;
return JSON.stringify([["p", "pub-nip44", ciphertext]]);
nip44: {
async decrypt(_pubkey, ciphertext) {
decryptCalls.nip44 += 1;
return JSON.stringify([["p", "pub-nip44", ciphertext]]);
},
},
});
};
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000005");
await manager.loadSubscriptions("user-pubkey-123");
assert.deepEqual(
Array.from(manager.subscribedPubkeys),
@@ -292,10 +292,15 @@ test("loadSubscriptions falls back to nip44 when hinted", async () => {
nostrClient.writeRelays = originalWriteRelays;
nostrClient.pool = originalPool;
nostrClient.ensureExtensionPermissions = originalEnsurePermissions;
if (typeof originalWindowNostr === "undefined") {
delete globalThis.window.nostr;
} else {
globalThis.window.nostr = originalWindowNostr;
}
if (!hadWindow) {
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
});
@@ -312,6 +317,12 @@ test("loadSubscriptions handles nip44.v2 decryptors", async () => {
const originalPool = nostrClient.pool;
const originalEnsurePermissions = nostrClient.ensureExtensionPermissions;
const hadWindow = typeof globalThis.window !== "undefined";
if (!hadWindow) {
globalThis.window = {};
}
const originalWindowNostr = globalThis.window.nostr;
const relayUrls = ["wss://relay-nip44-v2.example"];
nostrClient.relays = relayUrls;
nostrClient.writeRelays = relayUrls;
@@ -332,16 +343,19 @@ test("loadSubscriptions handles nip44.v2 decryptors", async () => {
nostrClient.ensureExtensionPermissions = async () => ({ ok: true });
const decryptCalls = { nip04: 0, nip44: 0, nip44_v2: 0 };
setActiveSigner({
pubkey: "0000000000000000000000000000000000000000000000000000000000000006",
async nip44Decrypt(_pubkey, ciphertext) {
decryptCalls.nip44_v2 += 1;
return JSON.stringify([["p", "pub-nip44-v2"], ["t", ciphertext]]);
globalThis.window.nostr = {
nip44: {
v2: {
async decrypt(_pubkey, ciphertext) {
decryptCalls.nip44_v2 += 1;
return JSON.stringify([["p", "pub-nip44-v2"], ["t", ciphertext]]);
},
},
},
});
};
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000006");
await manager.loadSubscriptions("user-pubkey-123");
assert.deepEqual(
Array.from(manager.subscribedPubkeys),
@@ -370,10 +384,15 @@ test("loadSubscriptions handles nip44.v2 decryptors", async () => {
nostrClient.writeRelays = originalWriteRelays;
nostrClient.pool = originalPool;
nostrClient.ensureExtensionPermissions = originalEnsurePermissions;
if (typeof originalWindowNostr === "undefined") {
delete globalThis.window.nostr;
} else {
globalThis.window.nostr = originalWindowNostr;
}
if (!hadWindow) {
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
});
@@ -390,6 +409,12 @@ test("loadSubscriptions prefers nip44 decryptors when both are available", async
const originalPool = nostrClient.pool;
const originalEnsurePermissions = nostrClient.ensureExtensionPermissions;
const hadWindow = typeof globalThis.window !== "undefined";
if (!hadWindow) {
globalThis.window = {};
}
const originalWindowNostr = globalThis.window.nostr;
const relayUrls = ["wss://relay-nip44-pref.example"];
nostrClient.relays = relayUrls;
nostrClient.writeRelays = relayUrls;
@@ -410,20 +435,25 @@ test("loadSubscriptions prefers nip44 decryptors when both are available", async
nostrClient.ensureExtensionPermissions = async () => ({ ok: true });
const decryptCalls = { nip04: 0, nip44: 0 };
setActiveSigner({
pubkey: "0000000000000000000000000000000000000000000000000000000000000003",
async nip04Decrypt() {
decryptCalls.nip04 += 1;
return JSON.stringify([["p", "pub-nip04"]]);
globalThis.window.nostr = {
nip04: {
async decrypt() {
decryptCalls.nip04 += 1;
return JSON.stringify([["p", "pub-nip04"]]);
},
},
async nip44Decrypt(_pubkey, ciphertext) {
decryptCalls.nip44 += 1;
return JSON.stringify([["p", "pub-nip44-pref", ciphertext]]);
nip44: {
v2: {
async decrypt(_pubkey, ciphertext) {
decryptCalls.nip44 += 1;
return JSON.stringify([["p", "pub-nip44-pref", ciphertext]]);
},
},
},
});
};
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000003");
await manager.loadSubscriptions("user-pubkey-123");
assert.deepEqual(
Array.from(manager.subscribedPubkeys),
@@ -437,10 +467,15 @@ test("loadSubscriptions prefers nip44 decryptors when both are available", async
nostrClient.writeRelays = originalWriteRelays;
nostrClient.pool = originalPool;
nostrClient.ensureExtensionPermissions = originalEnsurePermissions;
if (typeof originalWindowNostr === "undefined") {
delete globalThis.window.nostr;
} else {
globalThis.window.nostr = originalWindowNostr;
}
if (!hadWindow) {
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
});
@@ -491,7 +526,7 @@ test(
const decryptCalls = [];
setActiveSigner({
pubkey: "0000000000000000000000000000000000000000000000000000000000000004",
pubkey: "user-pubkey-123",
async nip04Decrypt(pubkey, ciphertext) {
decryptCalls.push({ pubkey, ciphertext });
return JSON.stringify([["p", "pub-direct"]]);
@@ -499,13 +534,13 @@ test(
});
try {
await manager.loadSubscriptions("0000000000000000000000000000000000000000000000000000000000000004");
await manager.loadSubscriptions("user-pubkey-123");
assert.equal(permissionCalls, 0, "should not request extension permissions");
assert.equal(decryptCalls.length, 1, "signer decrypt should be invoked once");
assert.deepEqual(
decryptCalls[0],
{ pubkey: "0000000000000000000000000000000000000000000000000000000000000004", ciphertext: "cipher-direct" },
{ pubkey: "user-pubkey-123", ciphertext: "cipher-direct" },
"signer decrypt should receive the expected arguments",
);
assert.deepEqual(
@@ -528,9 +563,6 @@ test(
delete globalThis.window;
}
localStorage.clear();
profileCache.memoryCache.clear();
profileCache.activePubkey = null;
clearActiveSigner();
}
},
);