-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: [성능 개선] ERD 노드 검색 시 문자열 병합 및 WeakMap 캐싱을 통한 최적화 #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,25 @@ import type { Node } from "@xyflow/react"; | |
|
|
||
| import type { TableNodeData } from "./convert"; | ||
|
|
||
| function fieldIncludes(value: string | null | undefined, term: string): boolean { | ||
| return Boolean(value && value.toLocaleLowerCase().includes(term)); | ||
| } | ||
| const nodeSearchTextCache = new WeakMap<TableNodeData, string>(); | ||
|
|
||
| function getNodeSearchText(node: Node<TableNodeData>): string { | ||
| let text = nodeSearchTextCache.get(node.data); | ||
| if (text !== undefined) return text; | ||
|
|
||
| function nodeIncludesTerm(node: Node<TableNodeData>, term: string): boolean { | ||
| if (fieldIncludes(node.data.title, term)) return true; | ||
| if (fieldIncludes(node.data.comment, term)) return true; | ||
| const parts: string[] = []; | ||
| if (node.data.title) parts.push(node.data.title); | ||
| if (node.data.comment) parts.push(node.data.comment); | ||
|
|
||
| for (const column of node.data.columns) { | ||
| if (fieldIncludes(column.column_name, term)) return true; | ||
| if (fieldIncludes(column.data_type, term)) return true; | ||
| if (fieldIncludes(column.column_comment, term)) return true; | ||
| for (const col of node.data.columns) { | ||
| if (col.column_name) parts.push(col.column_name); | ||
| if (col.data_type) parts.push(col.data_type); | ||
| if (col.column_comment) parts.push(col.column_comment); | ||
| } | ||
|
|
||
| return false; | ||
| text = parts.join(" ").toLocaleLowerCase(); | ||
| nodeSearchTextCache.set(node.data, text); | ||
| return text; | ||
| } | ||
|
|
||
| export function tableNodeMatchesSearch( | ||
|
|
@@ -29,7 +33,9 @@ export function tableNodeMatchesSearch( | |
| new Set(search.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean)), | ||
| ); | ||
| if (terms.length === 0) return false; | ||
| return terms.every((term) => nodeIncludesTerm(node, term)); | ||
|
|
||
| const nodeText = getNodeSearchText(node); | ||
| return terms.every((term) => nodeText.includes(term)); | ||
|
Comment on lines
33
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Combined-haystack search matches per-field results Search now joins all node fields with a space and calls (Refers to this code) Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| export function findSearchMatchedNodeIds( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Search-text cache cannot go stale
nodeSearchTextCacheis keyed onnode.data. Every content edit in App.tsx builds a new data object via...node.dataspread, so the key changes whenever searchable text changes. Drag updates keep the same reference, yielding a correct cache hit.Was this helpful? React with 👍 or 👎 to provide feedback.