mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
Fix inefficient queryClient update when relay URL changes
This commit is contained in:
3 files changed
+4
-4
No files matched your search
@@ -20,10 +20,10 @@ const NostrProvider: React.FC<NostrProviderProps> = (props) => {
|
|||||||
// Use refs so the pool always has the latest data
|
// Use refs so the pool always has the latest data
|
||||||
const relayUrl = useRef<string>(config.relayUrl);
|
const relayUrl = useRef<string>(config.relayUrl);
|
||||||
|
|
||||||
// Update refs when config changes
|
// Invalidate Nostr queries when relayUrl changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
relayUrl.current = config.relayUrl;
|
relayUrl.current = config.relayUrl;
|
||||||
queryClient.resetQueries();
|
queryClient.invalidateQueries({ queryKey: ['nostr'] });
|
||||||
}, [config.relayUrl, queryClient]);
|
}, [config.relayUrl, queryClient]);
|
||||||
|
|
||||||
// Initialize NPool only once
|
// Initialize NPool only once
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export function useComments(root: NostrEvent | URL, limit?: number) {
|
|||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['comments', root instanceof URL ? root.toString() : root.id, limit],
|
queryKey: ['nostr', 'comments', root instanceof URL ? root.toString() : root.id, limit],
|
||||||
queryFn: async (c) => {
|
queryFn: async (c) => {
|
||||||
const filter: NostrFilter = { kinds: [1111] };
|
const filter: NostrFilter = { kinds: [1111] };
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function useLoggedInAccounts() {
|
|||||||
const { logins, setLogin, removeLogin } = useNostrLogin();
|
const { logins, setLogin, removeLogin } = useNostrLogin();
|
||||||
|
|
||||||
const { data: authors = [] } = useQuery({
|
const { data: authors = [] } = useQuery({
|
||||||
queryKey: ['logins', logins.map((l) => l.id).join(';')],
|
queryKey: ['nostr', 'logins', logins.map((l) => l.id).join(';')],
|
||||||
queryFn: async ({ signal }) => {
|
queryFn: async ({ signal }) => {
|
||||||
const events = await nostr.query(
|
const events = await nostr.query(
|
||||||
[{ kinds: [0], authors: logins.map((l) => l.pubkey) }],
|
[{ kinds: [0], authors: logins.map((l) => l.pubkey) }],
|
||||||
|
|||||||
Reference in new issue
Block a user