perf: incremental transcript updates via WebSocket, eliminate polling
- Replace 1500ms polling with fs.watch recursive (reliable on Windows) - Enrich WS broadcast with newContent delta + session metadata - Client appends incrementally instead of 2 sequential HTTP requests - Pre-initialize Tauri HTTP plugin at module load to avoid dynamic import overhead - Per-file debounce timers (150ms) instead of single shared timer - Size-based validation for safe incremental appends with HTTP fallback
This commit is contained in:
@@ -17,6 +17,9 @@ export function isMobileTauri(): boolean {
|
||||
// Server URL storage (in-memory, loaded from Tauri store on init)
|
||||
let _serverUrl = ''
|
||||
|
||||
// Cached Tauri HTTP fetch function (avoid dynamic import on every request)
|
||||
let _tauriFetch: typeof fetch | null = null
|
||||
|
||||
export function getServerUrl(): string {
|
||||
return _serverUrl
|
||||
}
|
||||
@@ -55,10 +58,13 @@ export async function apiFetch(input: string | URL | Request, init?: RequestInit
|
||||
// Resolve URL
|
||||
const url = typeof input === 'string' ? resolveUrl(input) : input
|
||||
|
||||
// Use Tauri HTTP plugin for cross-origin requests
|
||||
// Use Tauri HTTP plugin for cross-origin requests (cached after first load)
|
||||
try {
|
||||
const { fetch: tauriFetch } = await import('@tauri-apps/plugin-http')
|
||||
return tauriFetch(url, init)
|
||||
if (!_tauriFetch) {
|
||||
const { fetch: tauriFetch } = await import('@tauri-apps/plugin-http')
|
||||
_tauriFetch = tauriFetch
|
||||
}
|
||||
return _tauriFetch(url, init)
|
||||
} catch (e) {
|
||||
// Fallback to native fetch if plugin fails
|
||||
console.warn('[Tauri] HTTP plugin failed, falling back to fetch:', e)
|
||||
@@ -66,6 +72,26 @@ export async function apiFetch(input: string | URL | Request, init?: RequestInit
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Eagerly initialize the Tauri HTTP plugin to avoid dynamic import overhead
|
||||
* on the first apiFetch call. Call this once at app startup.
|
||||
*/
|
||||
export async function initTauriFetch() {
|
||||
if (!isTauri || _tauriFetch) return
|
||||
try {
|
||||
const { fetch: tauriFetch } = await import('@tauri-apps/plugin-http')
|
||||
_tauriFetch = tauriFetch
|
||||
console.log('[Tauri] HTTP plugin pre-initialized')
|
||||
} catch (e) {
|
||||
console.warn('[Tauri] Failed to pre-init HTTP plugin:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-init on module load in Tauri mode
|
||||
if (isTauri) {
|
||||
initTauriFetch()
|
||||
}
|
||||
|
||||
// Dynamic plugin imports (only used behind isTauri checks)
|
||||
export async function getTauriStore() {
|
||||
const { LazyStore } = await import('@tauri-apps/plugin-store')
|
||||
|
||||
Reference in New Issue
Block a user