mirror of
https://github.com/hoornet/vega.git
synced 2026-05-10 22:29:11 -07:00
SQLite-backed followers cache and instant own-profile load
Followers now load instantly from SQLite on startup, then merge relay results in background. Own profile name/picture loads from DB cache so sidebar badge never shows raw npub on slow relays.
This commit is contained in:
@@ -9,6 +9,7 @@ import { useUIStore } from "./ui";
|
||||
import { useNotificationsStore } from "./notifications";
|
||||
import { useFeedStore } from "./feed";
|
||||
import { startNotificationPoller, stopNotificationPoller } from "../lib/notificationPoller";
|
||||
import { dbLoadProfile } from "../lib/db";
|
||||
|
||||
export interface SavedAccount {
|
||||
pubkey: string;
|
||||
@@ -418,6 +419,24 @@ export const useUserStore = create<UserState>((set, get) => ({
|
||||
const { pubkey } = get();
|
||||
if (!pubkey) return;
|
||||
|
||||
// Instant: load from SQLite cache so name/picture show immediately
|
||||
if (!get().profile) {
|
||||
try {
|
||||
const cached = await dbLoadProfile(pubkey);
|
||||
if (cached && !get().profile) {
|
||||
const parsed = JSON.parse(cached);
|
||||
set({ profile: parsed });
|
||||
const name = parsed?.displayName || parsed?.name;
|
||||
const picture = parsed?.picture;
|
||||
if (name) {
|
||||
const accounts = upsertAccount(get().accounts, { pubkey, npub: get().npub!, name, picture });
|
||||
persistAccounts(accounts);
|
||||
set({ accounts });
|
||||
}
|
||||
}
|
||||
} catch { /* cache miss is fine */ }
|
||||
}
|
||||
|
||||
try {
|
||||
const ndk = getNDK();
|
||||
const user = ndk.getUser({ pubkey });
|
||||
|
||||
Reference in New Issue
Block a user