diff --git a/ROADMAP.md b/ROADMAP.md index 20752384..ebc25c36 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,5 +1,7 @@ # Current +- [ ] formatTimestamp is expensive, cache it by assigning to events +- [ ] Fix hover on notes in modal - [ ] Show loading/success on zap invoice screen - [ ] Fix iOS/safari/firefox - [ ] Show more link on long notes (rather than just an ellipsis) diff --git a/package-lock.json b/package-lock.json index 2a7f500a..69790b88 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 51645da1..299c65fd 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "husky": "^8.0.3", "localforage": "^1.10.0", "localforage-memoryStorageDriver": "^0.9.2", + "lru-cache": "^7.18.3", "nostr-tools": "^1.7.4", "npm-run-all": "^4.1.5", "qr-scanner": "^1.4.2", diff --git a/src/agent/keys.ts b/src/agent/keys.ts index 5af1c16f..f27b2db9 100644 --- a/src/agent/keys.ts +++ b/src/agent/keys.ts @@ -9,25 +9,6 @@ const privkey = synced('agent/keys/privkey') const getExtension = () => (window as {nostr?: any}).nostr const canSign = () => ['privkey', 'extension'].includes(get(method)) -// For backwards compatibility, if method isn't set but we're logged in, set it -setTimeout(() => { - method.update($method => { - if ($method) { - return $method - } - - if (get(privkey)) { - return 'privkey' - } - - if (get(pubkey)) { - return getExtension() ? 'extension' : 'pubkey' - } - - return null - }) -}, 100) - const login = ($method, key) => { method.set($method) diff --git a/src/agent/relays.ts b/src/agent/relays.ts index 017dddf8..80fb7ab7 100644 --- a/src/agent/relays.ts +++ b/src/agent/relays.ts @@ -1,4 +1,5 @@ import type {Relay} from 'src/util/types' +import LRUCache from 'lru-cache' import {warn} from 'src/util/logger' import {filter, pipe, pick, groupBy, objOf, map, assoc, sortBy, uniqBy, prop} from 'ramda' import {first, createMap} from 'hurdak/lib/hurdak' @@ -49,11 +50,19 @@ export const initializeRelayList = async () => { // Pubkey relays +const _getPubkeyRelaysCache = new LRUCache({max: 1000}) + export const getPubkeyRelays = (pubkey, mode = null, routes = null) => { const filter = mode ? {pubkey, mode} : {pubkey} - const filteredRoutes = routes || database.routes.all(filter) + const key = [mode, pubkey].join(':') - return sortByScore(map(pick(['url', 'score']), filteredRoutes)) + let result = routes || _getPubkeyRelaysCache.get(key) + if (!result) { + result = database.routes.all(filter) + _getPubkeyRelaysCache.set(key, result) + } + + return sortByScore(map(pick(['url', 'score']), result)) } export const getPubkeyReadRelays = pubkey => getPubkeyRelays(pubkey, 'read') diff --git a/src/views/notes/Note.svelte b/src/views/notes/Note.svelte index 2b7d970c..2f1279b3 100644 --- a/src/views/notes/Note.svelte +++ b/src/views/notes/Note.svelte @@ -392,26 +392,26 @@
- - - -
{ showRelays = true }}>