Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ Optimized metric route processing to O(N) by creating a mapping of routes direct
## 2024-07-13 - [Optimize Export Dictionary FK lookups]
**Learning:** Found O(N * C * E) performance bottleneck in ERD export dictionaries due to repeated array searching with `edges.some()` inside a nested loop over nodes and columns.
**Action:** Replace repeated linear array scans for edges by precomputing O(1) Set lookups of foreign key column handles per node before looping.
## 2024-07-31 - Optimize DBML Import Column Parsing
**Learning:** When generating schema snapshots during DBML imports, calculating occurrences using inline generator expressions (e.g., `sum(1 for ...)`) within a loop causes O(N^2) time complexity because it scans the growing list on every iteration.
**Action:** Use an auxiliary O(1) dictionary counter (e.g., `col_count_by_oid = {}`) instead of repeatedly scanning the array when assigning incremental counters like positions or ordinals in loops.
6 changes: 5 additions & 1 deletion backend/app/spec/dbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def parse_dbml(text: str) -> dict[str, Any]:
fk_specs: list[tuple[str, str, str, str, str, str]] = [] # child s/t/c, parent s/t/c

oid_by_table: dict[tuple[str, str], int] = {}
col_count_by_oid: dict[int, int] = {} # O(1) tracker for column positions
next_oid = 1
current: tuple[str, str] | None = None
in_ignored_block = 0
Expand Down Expand Up @@ -207,11 +208,14 @@ def parse_dbml(text: str) -> dict[str, Any]:
settings = (cm.group("settings") or "").lower()
oid = oid_by_table[current]
is_pk = bool(re.search(r"\bpk\b|primary\s+key", settings))
# O(1) dictionary counter instead of O(N^2) inline generator
col_count_by_oid[oid] = col_count_by_oid.get(oid, 0) + 1

columns.append(
{
"relation_oid": oid,
"column_name": col_name,
"column_position": sum(1 for c in columns if c["relation_oid"] == oid) + 1,
"column_position": col_count_by_oid[oid],
"data_type": cm.group("type"),
"is_not_null": is_pk or "not null" in settings,
"has_default": "default:" in settings,
Expand Down
Loading