WeKnora/frontend
lyingbug 745a22d066
refactor(frontend): drop TTL resource caches and remove duplicate startup requests (#3562)
* refactor(frontend): drop TTL resource caches and remove duplicate startup requests

Space-level resource stores (chatResources / editorResources / organization)
cached lists for 60s. Pages that own the data bypassed the cache with force,
while side consumers (chat input bar, selectors) read stale values and relied
on a web of indirect refresh signals. Replace the TTL with in-flight
deduplication plus explicit invalidation:

- add stores/resourceCache.ts: createCachedResource (one request in flight
  per resource, force queues behind it, invalidate/markLoaded discard stale
  responses) and createKeyedSnapshotCache for per-id details
- rebuild chatResources / editorResources on those primitives; organization
  store drops its loadedAt timestamps and uses the request coordinator only
- isFresh -> isLoaded (only "has a snapshot" is meaningful now)

Fix concrete duplicates found on the way:

- /auth/me was fetched twice on every cold load (main.ts + UserMenu); auth
  store now dedupes in-flight calls and exposes ensureAuthMe, router hydrate
  reuses refreshFromAuthMe instead of a second copy of the persist logic
- /system/info was fetched by menu.vue directly next to editorResources
- /platform/settings rendered Settings.vue as the route component while the
  platform layout already mounts it, so two modals were visible and every
  settings panel request ran twice; the route now renders an empty view
- components that called listKnowledgeBases / listAgents / getParserEngines /
  getPromptTemplates directly now go through the stores
- Input-field no longer force-refreshes models and web-search providers on
  "settings closed" / "left settings route"; WebSearchSettings writes back to
  the shared snapshot and useTenantModelReadiness derives from the store

Measured with a mock backend: cold load 19 -> 18 requests (/auth/me once),
settings model panel 3 -> 2 (one modal), route changes now refetch lists
(creatChat 3 -> 9, back to KB list 0 -> 4) instead of serving 60s-old data.

* fix(frontend): fence stale responses in the resource caches and /auth/me refresh

Review follow-ups on the TTL removal:

- createKeyedSnapshotCache tracks a per-key revision; invalidate() and a
  force read both advance it, so a response that lands after invalidation
  or behind a newer request is handed to its caller but never written back
  into the snapshot. Previously a KB detail read still in flight during
  save could re-pin the pre-save detail until the next explicit invalidate.
- ensureKnowledgeBases / ensureAgents no longer reject when the shared
  resource fetch fails; the own list is already applied and the previous
  shared snapshot is kept. Callers migrated onto the store (manual editor,
  KB selector, FAQ manager, API integration page) had independent failure
  handling before. McpServerIntegrationSettings shows empty lists on
  failure instead of the last snapshot.
- /auth/me refresh is sequenced via a new createSequencedRefresh helper:
  refreshFromAuthMe() always resolves on a request issued after the call
  (queued behind an in-flight one), ensureAuthMe() shares in-flight, and
  logout() invalidates so a late response cannot re-apply the old session.

Tests: keyed cache invalidate-during-flight and force-overlap; sequencer
refresh ordering, invalidate after logout, and recovery after a failed
in-flight request.

* fix(frontend): refetch models after publishing a catalog change

invalidate() no longer triggers a refetch and the chat input stopped
reloading models when settings close, so the reasoning-level selector kept
stale capabilities after a catalog publish. Force-refresh the snapshot.
2026-09-25 22:22:48 +08:00
..
public feat(i18n): add Japanese (ja-JP) locale support (#3080) 2026-09-07 19:20:41 +08:00
scripts feat(browser): add picture-in-picture task preview 2026-09-12 11:11:36 +08:00
src refactor(frontend): drop TTL resource caches and remove duplicate startup requests (#3562) 2026-09-25 22:22:48 +08:00
.dockerignore feat(ui): multi-stage Docker frontend build (no host npm) (#3074) 2026-09-07 19:33:57 +08:00
.gitignore init commit 2025-08-05 15:08:07 +08:00
Dockerfile chore: remove vendored archives and unused Python helpers 2026-09-16 15:49:36 +08:00
docker-entrypoint.sh feat(i18n): add Japanese (ja-JP) locale support (#3080) 2026-09-07 19:20:41 +08:00
embed.html feat(embed): add widget, visitor chat, and management UI (#1657) 2026-06-12 23:10:39 +08:00
env.d.ts feat(frontend): inject commit ID into frontend build for version tracking 2026-06-09 18:08:57 +08:00
index.html fix(frontend): bundle tdesign-icons sprite locally for offline deploys 2026-04-23 18:21:49 +08:00
mcpProxy.test.ts fix(mcp): proxy server endpoints through frontend gateways 2026-09-22 17:36:03 +08:00
nginx-api-proxy.conf fix(mcp): proxy server endpoints through frontend gateways 2026-09-22 17:36:03 +08:00
nginx-http.conf feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
nginx.conf docs: 迁移有效文档至 website-docs 并清理旧文档 (#3580) 2026-09-22 23:25:40 +08:00
package-lock.json feat(chat): open cited documents at the cited passage (#3700) 2026-09-25 13:26:16 +08:00
package.json feat(chat): open cited documents at the cited passage (#3700) 2026-09-25 13:26:16 +08:00
package.json.md5 fix: update environment configuration for debugging and logging, enhance SQLite FTS5 table management, and improve API base URL handling 2026-04-11 18:51:16 +08:00
pnpm-workspace.yaml fix(frontend): configure pnpm v11 build approvals in workspace file 2026-05-08 16:34:33 +08:00
tsconfig.app.json fix lint and test failures 2026-07-01 17:31:42 +08:00
tsconfig.json init commit 2025-08-05 15:08:07 +08:00
tsconfig.node.json init commit 2025-08-05 15:08:07 +08:00
vite.config.ts fix(mcp): proxy server endpoints through frontend gateways 2026-09-22 17:36:03 +08:00