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:
Jure
2026-03-29 20:28:25 +02:00
parent 2fed4e3e85
commit d450f8fdeb
6 changed files with 108 additions and 8 deletions

View File

@@ -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 });