mirror of
https://github.com/coracle-social/coracle.git
synced 2024-10-06 11:43:30 +00:00
Clean up reaction buttons, cache relays for performance
This commit is contained in:
parent
2ecfd56a14
commit
7d5f132e1f
@ -1,5 +1,7 @@
|
|||||||
# Current
|
# Current
|
||||||
|
|
||||||
|
- [ ] formatTimestamp is expensive, cache it by assigning to events
|
||||||
|
- [ ] Fix hover on notes in modal
|
||||||
- [ ] Show loading/success on zap invoice screen
|
- [ ] Show loading/success on zap invoice screen
|
||||||
- [ ] Fix iOS/safari/firefox
|
- [ ] Fix iOS/safari/firefox
|
||||||
- [ ] Show more link on long notes (rather than just an ellipsis)
|
- [ ] Show more link on long notes (rather than just an ellipsis)
|
||||||
|
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -38,6 +38,7 @@
|
|||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"localforage-memoryStorageDriver": "^0.9.2",
|
"localforage-memoryStorageDriver": "^0.9.2",
|
||||||
|
"lru-cache": "^7.18.3",
|
||||||
"nostr-tools": "^1.7.4",
|
"nostr-tools": "^1.7.4",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"qr-scanner": "^1.4.2",
|
"qr-scanner": "^1.4.2",
|
||||||
|
@ -9,25 +9,6 @@ const privkey = synced('agent/keys/privkey')
|
|||||||
const getExtension = () => (window as {nostr?: any}).nostr
|
const getExtension = () => (window as {nostr?: any}).nostr
|
||||||
const canSign = () => ['privkey', 'extension'].includes(get(method))
|
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) => {
|
const login = ($method, key) => {
|
||||||
method.set($method)
|
method.set($method)
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type {Relay} from 'src/util/types'
|
import type {Relay} from 'src/util/types'
|
||||||
|
import LRUCache from 'lru-cache'
|
||||||
import {warn} from 'src/util/logger'
|
import {warn} from 'src/util/logger'
|
||||||
import {filter, pipe, pick, groupBy, objOf, map, assoc, sortBy, uniqBy, prop} from 'ramda'
|
import {filter, pipe, pick, groupBy, objOf, map, assoc, sortBy, uniqBy, prop} from 'ramda'
|
||||||
import {first, createMap} from 'hurdak/lib/hurdak'
|
import {first, createMap} from 'hurdak/lib/hurdak'
|
||||||
@ -49,11 +50,19 @@ export const initializeRelayList = async () => {
|
|||||||
|
|
||||||
// Pubkey relays
|
// Pubkey relays
|
||||||
|
|
||||||
|
const _getPubkeyRelaysCache = new LRUCache({max: 1000})
|
||||||
|
|
||||||
export const getPubkeyRelays = (pubkey, mode = null, routes = null) => {
|
export const getPubkeyRelays = (pubkey, mode = null, routes = null) => {
|
||||||
const filter = mode ? {pubkey, mode} : {pubkey}
|
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')
|
export const getPubkeyReadRelays = pubkey => getPubkeyRelays(pubkey, 'read')
|
||||||
|
@ -392,26 +392,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between text-light">
|
<div class="flex justify-between text-light">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<button class="w-16" on:click|stopPropagation={startReply}>
|
<button class="w-16 text-left" on:click|stopPropagation={startReply}>
|
||||||
<i class="fa fa-reply cursor-pointer" />
|
<i class="fa fa-reply cursor-pointer" />
|
||||||
{$repliesCount}
|
{$repliesCount}
|
||||||
</button>
|
</button>
|
||||||
<button class="w-16" class:text-accent={like}
|
<button class="w-16 text-left" class:text-accent={like}
|
||||||
on:click|stopPropagation={() => like ? deleteReaction(like) : react("+")}>
|
on:click|stopPropagation={() => like ? deleteReaction(like) : react("+")}>
|
||||||
<i class={cx('fa fa-heart cursor-pointer', {'fa-beat fa-beat-custom': like})} />
|
<i class={cx('fa fa-heart cursor-pointer', {'fa-beat fa-beat-custom': like})} />
|
||||||
{$likesCount}
|
{$likesCount}
|
||||||
</button>
|
</button>
|
||||||
<button class="w-20" class:text-accent={zapped} on:click|stopPropagation={startZap}>
|
<button class="w-20 text-left" class:text-accent={zapped} on:click|stopPropagation={startZap}>
|
||||||
<i class={cx("fa fa-bolt cursor-pointer", {'pointer-events-none opacity-50': !canZap})} />
|
<i class={cx("fa fa-bolt cursor-pointer", {'pointer-events-none opacity-50': !canZap})} />
|
||||||
{formatSats($zapsTotal)}
|
{formatSats($zapsTotal)}
|
||||||
</button>
|
</button>
|
||||||
<button class="w-16" on:click|stopPropagation={() => react("-")}>
|
<button class="w-16 text-left" on:click|stopPropagation={() => react("-")}>
|
||||||
<i class="fa fa-flag cursor-pointer" />
|
<i class="fa fa-flag cursor-pointer" />
|
||||||
{$flagsCount}
|
{$flagsCount}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="cursor-pointer flex gap-1 items-center"
|
class="cursor-pointer gap-1 items-center hidden sm:flex"
|
||||||
on:click|stopPropagation={() => { showRelays = true }}>
|
on:click|stopPropagation={() => { showRelays = true }}>
|
||||||
<i class="fa fa-server" />
|
<i class="fa fa-server" />
|
||||||
<div
|
<div
|
||||||
|
Loading…
Reference in New Issue
Block a user