From 096de9b7f4fd963e920f17cc629266c6d56c04fe Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:16:52 +0800 Subject: [PATCH] refactor(connections): align perf replay with visible row derivation --- scripts/perf/scenes.tsx | 10 ++- .../connection/connection-row-item.tsx | 2 +- .../connection/connection-row-view.ts | 65 ------------------- 3 files changed, 5 insertions(+), 72 deletions(-) diff --git a/scripts/perf/scenes.tsx b/scripts/perf/scenes.tsx index 02992fec5..5c349c6fc 100644 --- a/scripts/perf/scenes.tsx +++ b/scripts/perf/scenes.tsx @@ -6,8 +6,7 @@ import { createRoot } from 'react-dom/client' import { SWRConfig } from 'swr' import { VirtualList } from '../../src/components/base/virtual-list' -import { ConnectionRowItem } from '../../src/components/connection/connection-row-item' -import { useConnectionRowViews } from '../../src/components/connection/connection-row-view' +import { VisibleConnectionRowItem } from '../../src/components/connection/connection-row-item' import LogItem from '../../src/components/log/log-item' import { initializeLanguage } from '../../src/services/i18n' import { setPreloadConfig } from '../../src/services/preload' @@ -35,10 +34,9 @@ export function Components() { }), [], ) - const rows = useConnectionRowViews(connections) return ( @@ -48,8 +46,8 @@ export function Components() { searchState={searchState} /> ) : ( - {}} /> diff --git a/src/components/connection/connection-row-item.tsx b/src/components/connection/connection-row-item.tsx index 9a9eff360..661b8cc3a 100644 --- a/src/components/connection/connection-row-item.tsx +++ b/src/components/connection/connection-row-item.tsx @@ -73,7 +73,7 @@ const actionStyle = { transform: 'translateY(-50%)', } as const -export const ConnectionRowItem = memo( +const ConnectionRowItem = memo( function ConnectionRowItem({ row, closed, onShowDetail }: Props) { const { t } = useTranslation() const onDelete = useLockFn(async () => closeConnection(row.id)) diff --git a/src/components/connection/connection-row-view.ts b/src/components/connection/connection-row-view.ts index 4bfba7809..d5532ee3d 100644 --- a/src/components/connection/connection-row-view.ts +++ b/src/components/connection/connection-row-view.ts @@ -1,5 +1,3 @@ -import { useMemo, useRef } from 'react' - const TRAFFIC_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] export interface ConnectionRowView { @@ -114,66 +112,3 @@ export const createConnectionRowView = (connection: IConnectionsItem) => { searchableProcess: connection.metadata.process || '', } satisfies ConnectionRowView } - -const sameConnectionRowView = ( - left: ConnectionRowView, - right: ConnectionRowView, -) => - left.host === right.host && - left.process === right.process && - left.network === right.network && - left.type === right.type && - left.chains === right.chains && - left.rule === right.rule && - left.time === right.time && - left.source === right.source && - left.destination === right.destination && - left.uploadText === right.uploadText && - left.downloadText === right.downloadText && - left.uploadSpeedText === right.uploadSpeedText && - left.downloadSpeedText === right.downloadSpeedText && - left.upload === right.upload && - left.download === right.download && - left.uploadSpeed === right.uploadSpeed && - left.downloadSpeed === right.downloadSpeed && - left.searchableHost === right.searchableHost && - left.searchableDestinationIP === right.searchableDestinationIP && - left.searchableProcess === right.searchableProcess - -export const useConnectionRowViews = (connections: IConnectionsItem[]) => { - const previousRowsRef = useRef(new Map()) - const previousConnectionsRef = useRef(new Map()) - - return useMemo(() => { - const previousRows = previousRowsRef.current - const previousConnections = previousConnectionsRef.current - const nextRows = new Map() - const nextConnections = new Map() - const rows: ConnectionRowView[] = [] - - connections.forEach((connection) => { - nextConnections.set(connection.id, connection) - - const previousRow = previousRows.get(connection.id) - const previousConnection = previousConnections.get(connection.id) - - let row: ConnectionRowView - if (previousRow && previousConnection === connection) { - row = previousRow - } else { - const nextRow = createConnectionRowView(connection) - row = - previousRow && sameConnectionRowView(previousRow, nextRow) - ? previousRow - : nextRow - } - - nextRows.set(connection.id, row) - rows.push(row) - }) - - previousRowsRef.current = nextRows - previousConnectionsRef.current = nextConnections - return rows - }, [connections]) -}