Skip to content

Commit 12582e3

Browse files
committed
exp pipeline v9 - depth limited crawling via options 2
1 parent 79ae385 commit 12582e3

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

experimental/pipeline_composition.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package experimental
33
func (m *Monster) MakeCompositionPipe(cleanPipe chan<- *Node) chan<- *ReqProp {
44
compositionPipe := make(chan *ReqProp)
55
structFunc := structurize
6-
if m.MaxDepth > 0 {
7-
structFunc = structurizeWithDepth
8-
}
6+
//if m.MaxDepth > 0 {
7+
// structFunc = structurizeWithDepth
8+
//}
99
go func() {
1010
for {
1111
select {

experimental/pipeline_requisition.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import "net/http"
44

55
func (m *Monster) MakeRequisitionPipe(parsePipe chan<- *Node, opAdapterPipe chan<- *Node) chan<- *Node {
66
requisitionPipe := make(chan *Node)
7-
go func() {
7+
isDepthLimited := false
8+
if m.MaxDepth > 0 {
9+
isDepthLimited = true
10+
}
11+
go func(isDepthLimited bool, maxDepth int) {
812
for {
913
select {
1014
case node := <-requisitionPipe:
1115
{
12-
go makeRequest(node, parsePipe, opAdapterPipe)
16+
go depthLimitedRequest(isDepthLimited, maxDepth, node, parsePipe, opAdapterPipe)
1317
}
1418
}
1519
}
16-
}()
20+
}(isDepthLimited, m.MaxDepth)
1721
return requisitionPipe
1822
}
1923

@@ -27,3 +31,10 @@ func makeRequest(node *Node, parsePipe chan<- *Node, opAdapterPipe chan<- *Node)
2731
}
2832
}
2933
}
34+
35+
func depthLimitedRequest(isDepthLimited bool, maxDepth int,
36+
node *Node, parsePipe chan<- *Node, opAdapterPipe chan<- *Node) {
37+
if !isDepthLimited || node.Depth <= maxDepth {
38+
makeRequest(node, parsePipe, opAdapterPipe)
39+
}
40+
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func runPipeline() {
6767

6868
func runPipelineWithOptions() {
6969
opt := &exp.Options{
70-
MaxDepth: 3,
70+
MaxDepth: 1,
7171
}
7272
crawler := exp.NewMonsterWithOptions(opt)
7373
opAdapterPipe := exp.GetOutputAdapterPipe()

0 commit comments

Comments
 (0)