mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-02 03:38:16 +08:00
⚡️ perf(frontend): 优化长时运行下的搜索与缓存占用
- 为 V2 cmd+k 搜索预建索引并限制初始/宽泛结果数量 - 清理冷数据库树和 DataViewer 长生命周期快照缓存 - 收紧运行时 SQL 日志预算并在 hydration 时压缩旧缓存
This commit is contained in:
@@ -280,8 +280,32 @@ type ViewerScrollSnapshot = {
|
||||
};
|
||||
|
||||
const viewerFilterSnapshotsByTab = new Map<string, ViewerFilterSnapshot>();
|
||||
const MAX_VIEWER_FILTER_SNAPSHOTS = 64;
|
||||
const VIEWER_SCROLL_SNAPSHOT_PERSIST_DELAY_MS = 160;
|
||||
|
||||
const trimViewerFilterSnapshots = () => {
|
||||
while (viewerFilterSnapshotsByTab.size > MAX_VIEWER_FILTER_SNAPSHOTS) {
|
||||
const oldestKey = viewerFilterSnapshotsByTab.keys().next().value;
|
||||
if (!oldestKey) {
|
||||
break;
|
||||
}
|
||||
viewerFilterSnapshotsByTab.delete(oldestKey);
|
||||
}
|
||||
};
|
||||
|
||||
const setViewerFilterSnapshot = (
|
||||
tabId: string,
|
||||
snapshot: ViewerFilterSnapshot,
|
||||
) => {
|
||||
const normalizedTabId = String(tabId || '').trim();
|
||||
if (!normalizedTabId) return;
|
||||
if (viewerFilterSnapshotsByTab.has(normalizedTabId)) {
|
||||
viewerFilterSnapshotsByTab.delete(normalizedTabId);
|
||||
}
|
||||
viewerFilterSnapshotsByTab.set(normalizedTabId, snapshot);
|
||||
trimViewerFilterSnapshots();
|
||||
};
|
||||
|
||||
const normalizeViewerFilterConditions = (conditions: FilterCondition[] | undefined): FilterCondition[] => {
|
||||
if (!Array.isArray(conditions)) return [];
|
||||
return conditions.map((cond) => ({
|
||||
@@ -380,7 +404,7 @@ const DataViewer: React.FC<{ tab: TabData; isActive?: boolean }> = React.memo(({
|
||||
const persistViewerSnapshot = useCallback((tabId: string, overrides?: Partial<ViewerFilterSnapshot>) => {
|
||||
const normalizedTabId = String(tabId || '').trim();
|
||||
if (!normalizedTabId) return;
|
||||
viewerFilterSnapshotsByTab.set(normalizedTabId, {
|
||||
setViewerFilterSnapshot(normalizedTabId, {
|
||||
showFilter,
|
||||
conditions: normalizeViewerFilterConditions(filterConditions),
|
||||
quickWhereCondition: normalizeQuickWhereCondition(quickWhereCondition),
|
||||
|
||||
Reference in New Issue
Block a user