Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor image and post link extraction to use iter #535

Merged
merged 1 commit into from
Sep 8, 2024
Merged
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
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
Loading