Skip to content

Commit

Permalink
Refactor image and post link extraction to use iter
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Sep 8, 2024
1 parent d2b1e88 commit 0677ba3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benchmarker/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: bin/benchmarker

bin/benchmarker: *.go checker/*.go
bin/benchmarker: *.go checker/*.go go.mod go.sum
go build -o bin/benchmarker
16 changes: 8 additions & 8 deletions benchmarker/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ func loadImages(s *checker.Session, imageURLs []string) {
}

func extractImages(doc *goquery.Document) []string {
imageURLs := []string{}
imageURLs := make([]string, 0, PostsPerPage)

doc.Find("img.isu-image").Each(func(_ int, selection *goquery.Selection) {
if url, ok := selection.Attr("src"); ok {
for _, el := range doc.Find("img.isu-image").EachIter() {
if url, ok := el.Attr("src"); ok {
imageURLs = append(imageURLs, url)
}
}).Length()
}

return imageURLs
}

func extractPostLinks(doc *goquery.Document) []string {
postLinks := []string{}
postLinks := make([]string, 0, PostsPerPage)

doc.Find("a.isu-post-permalink").Each(func(_ int, selection *goquery.Selection) {
if url, ok := selection.Attr("href"); ok {
for _, el := range doc.Find("a.isu-post-permalink").EachIter() {
if url, ok := el.Attr("href"); ok {
postLinks = append(postLinks, url)
}
}).Length()
}

return postLinks
}
Expand Down

0 comments on commit 0677ba3

Please sign in to comment.