Repository navigation
Go: parse HTML file - #16018
Go: parse HTML file#16018
Conversation
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughAdds HTML file parsing to the Go ingestion pipeline. A new ChangesHTML Parser Support
Sequence Diagram(s)sequenceDiagram
participant Caller
participant GetParser
participant NewHTMLParser
participant HTMLParser
participant html.Parse
participant WalkIterative
Caller->>GetParser: GetParser(fileType, config)
GetParser->>NewHTMLParser: NewHTMLParser("official")
NewHTMLParser-->>GetParser: *HTMLParser
GetParser-->>Caller: Parser interface
Caller->>HTMLParser: Parse(filename, data)
HTMLParser->>html.Parse: OfficialHTMLParse(data)
html.Parse-->>HTMLParser: root *html.Node
HTMLParser->>WalkIterative: WalkIterative(root)
WalkIterative-->>HTMLParser: node output printed
HTMLParser-->>Caller: nil
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/ingestion/parser/html_parser.go (1)
106-112: ⚡ Quick winAvoid O(n²) child reversal in iterative traversal.
Line 108 prepends into a slice for each child, which is quadratic for nodes with many siblings. Push children by iterating from
LastChildtoPrevSiblingand append directly.Proposed refactor
- var children []*html.Node - for child := current.node.FirstChild; child != nil; child = child.NextSibling { - children = append([]*html.Node{child}, children...) // Reverse order - } - for _, child := range children { - stack = append(stack, item{child, current.depth + 1}) - } + for child := current.node.LastChild; child != nil; child = child.PrevSibling { + stack = append(stack, item{child, current.depth + 1}) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/ingestion/parser/html_parser.go` around lines 106 - 112, The current code uses prepend operations (line 108: children = append([]*html.Node{child}, children...)) which creates O(n²) complexity for nodes with many siblings because each prepend requires copying the entire slice. Instead of iterating from FirstChild to NextSibling and prepending, iterate backwards from LastChild to PrevSibling and append directly to the children slice. This achieves the same reversal of child order while maintaining O(n) linear time complexity. Replace the forward iteration loop with a backward iteration that uses LastChild and PrevSibling, and change the append operation from prepend to a regular append.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/ingestion/parser/html_parser.go`:
- Around line 106-112: The current code uses prepend operations (line 108:
children = append([]*html.Node{child}, children...)) which creates O(n²)
complexity for nodes with many siblings because each prepend requires copying
the entire slice. Instead of iterating from FirstChild to NextSibling and
prepending, iterate backwards from LastChild to PrevSibling and append directly
to the children slice. This achieves the same reversal of child order while
maintaining O(n) linear time complexity. Replace the forward iteration loop with
a backward iteration that uses LastChild and PrevSibling, and change the append
operation from prepend to a regular append.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eb817375-2cd9-49ac-aa69-90e6e89e60f4
📒 Files selected for processing (3)
internal/ingestion/parser/html_parser.gointernal/ingestion/parser/type.gointernal/utility/file.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16018 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?