Skip to content

Commit 1bd2639

Browse files
committed
refactor recursive URL parsing
1 parent 9e8ebef commit 1bd2639

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

sitemap.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ func (s *S) parseAndFetchUrlsMultiThread(locations []string) {
437437
return
438438
}
439439
content = s.checkAndUnzipContent(content)
440-
_ = s.parse(loc, string(content))
440+
parsedLocations := s.parse(loc, string(content))
441+
if len(parsedLocations) > 0 {
442+
s.parseAndFetchUrlsMultiThread(parsedLocations)
443+
}
441444
}()
442445
}
443446
wg.Wait()
@@ -457,7 +460,10 @@ func (s *S) parseAndFetchUrlsSequential(locations []string) {
457460
continue
458461
}
459462
content = s.checkAndUnzipContent(content)
460-
_ = s.parse(location, string(content))
463+
parsedLocations := s.parse(location, string(content))
464+
if len(parsedLocations) > 0 {
465+
s.parseAndFetchUrlsSequential(parsedLocations)
466+
}
461467
}
462468
}
463469

sitemap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ func TestS_parseAndFetchUrlsMultiThread(t *testing.T) {
12811281
fmt.Sprintf("%s/sitemapindex-1.xml", server.URL),
12821282
fmt.Sprintf("%s/sitemap-04.xml", server.URL),
12831283
},
1284-
urlsCount: 1,
1284+
urlsCount: 7,
12851285
errsCount: 0,
12861286
},
12871287
}
@@ -1336,7 +1336,7 @@ func TestS_parseAndFetchUrlsSequential(t *testing.T) {
13361336
fmt.Sprintf("%s/sitemapindex-1.xml", server.URL),
13371337
fmt.Sprintf("%s/sitemap-04.xml", server.URL),
13381338
},
1339-
urlsCount: 1,
1339+
urlsCount: 7,
13401340
errsCount: 0,
13411341
},
13421342
}

0 commit comments

Comments
 (0)