Add embedded Nostr relay with catch-up sync on startup

Embedded relay (strfry-lite in Rust) stores events locally in SQLite.
On startup, syncs user notes, follow feed (24h), mentions (7d), and
profile/contacts from remote relays into the local relay. Uses since
timestamp for incremental syncs. Toggle in Settings with event count
and DB size display. Add webkit2gtk GPU acceleration workaround and
connectToRelays safety timeout for NDK hang.
This commit is contained in:
Jure
2026-04-01 12:10:11 +02:00
parent c1029327e7
commit e3f5020eeb
14 changed files with 1342 additions and 7 deletions

View File

@@ -5,6 +5,8 @@ import { seedReactionsCache } from "../hooks/useReactions";
import { useToastStore } from "./toast";
import { dbLoadFeed, dbSaveNotes } from "../lib/db";
import { diagWrapFetch, logDiag, startRelaySnapshots, getRelayStates } from "../lib/feedDiagnostics";
// Local relay imports deferred to avoid circular dependency
// import { isLocalRelayEnabled, connectLocalRelay } from "../lib/localRelay";
const TRENDING_CACHE_KEY = "wrystr_trending_cache";
const TRENDING_TTL = 10 * 60 * 1000; // 10 minutes
@@ -50,8 +52,30 @@ export const useFeedStore = create<FeedState>((set, get) => ({
try {
set({ error: null });
const connectStart = performance.now();
await connectToRelays();
// connectToRelays() can hang if NDK's instance.connect() never resolves — safety timeout
await Promise.race([
connectToRelays(),
new Promise<void>((resolve) => setTimeout(resolve, 15000)),
]);
set({ connected: true });
// Connect local embedded relay if enabled, then sync recent events
try {
const { isLocalRelayEnabled, connectLocalRelay, syncToLocalRelay } = await import("../lib/localRelay");
if (isLocalRelayEnabled()) {
await connectLocalRelay();
const { useUserStore } = await import("./user");
const { pubkey, follows } = useUserStore.getState();
if (pubkey) {
syncToLocalRelay(pubkey, follows).catch((err) =>
console.warn("[Vega] Local relay sync failed:", err),
);
}
}
} catch (err) {
console.warn("[Vega] Local relay setup failed:", err);
}
const connectMs = Math.round(performance.now() - connectStart);
logDiag({
ts: new Date().toISOString(),