fix/slow-page-load-due-to-authors-info-requests #14
No reviewers
Labels
No labels
Agent/Chrome-Android
Agent/Chrome-Desktop
Agent/Chrome-iOS
Agent/Firefox-Android
Agent/Firefox-Desktop
Agent/Firefox-iOS
Agent/Safari-Desktop
Agent/Safari-iOS
Code/Backend
Code/DevOps
Code/Frontend
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority/Critical
Priority/High
Priority/Low
Priority/Medium
Reviewed/Confirmed
Reviewed/Duplicate
Reviewed/Invalid
Reviewed/Won't Fix
Status/Abandoned
Status/Blocked
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
aniram/cidadon!14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/slow-page-load-due-to-authors-info-requests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
few changes needed, more caution with correct placement of call to close HTTP response body stream.
@ -13,2 +14,4 @@"golang.org/x/sync/errgroup")type authorsChannel struct {Remove unused struct
@ -60,3 +68,3 @@return}if resp.Body.Close() != nil { fmt.Println("project.go: could not close body stream after fetching projects by keyword") }if err := resp.Body.Close(); err != nil { fmt.Println("project.go: could not close body stream after fetching projects by keyword") }Defer closing the body immediately after creation of fd[1]
[1] https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body
@ -133,0 +103,4 @@p.CIDMainAuthor = mainAuthorp.CIDMainAuthor.CIDMember = memberWrapper.Memberm.Unlock()return errShould return nil
@ -139,0 +163,4 @@resp, err := client.Do(getReq)if err != nil {fmt.Printf("project.go: could not fetch member with URL %s due to %s\n", author.Uri, err)Should print author instead of member
@ -139,0 +156,4 @@getReq, err := http.NewRequest(http.MethodGet, author.Uri, nil)if err != nil {fmt.Printf("project.go: could not create GET request to fetch member data with URL %s due to %s\n", author.Uri, err)Should print author instead of member
@ -57,3 +65,3 @@fmt.Printf("project.go: could not read body from API's response to find projects by keyword due to %s\n", err)http.Error(w, "Something went wrong. Try again", http.StatusInternalServerError)resp.Body.Close()if err := resp.Body.Close(); err != nil { fmt.Println("project.go: could not close body stream after fetching projects by keyword") }Is this print helpful? Do we want to deal with the case where we cannot close the body stream?
And also the closing should happen immediately after creating the file descriptor[1] which in this case would be after
getReq, err := http.NewRequest("GET", keywordsUrls, nil)[1] https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body
@ -131,1 +95,4 @@fmt.Printf("project.go: could not marshal member due to %s\n", err)return err}resp.Body.Close()Defer closing the body immediately after creation of fd[1]
data, err = io.ReadAll(resp.Body)[1] https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body
@ -139,0 +144,4 @@var authorsWrapper model.AuthorsWrapperif err := json.Unmarshal(authorsData, &authorsWrapper); err != nil {fmt.Printf("project.go: could not marshal project's authors due to %s\n", err)resp.Body.Close()Defer closing the body immediately after creation of fd[1]
resp, err := client.Do(getReq)[1] https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body
@ -139,0 +147,4 @@resp.Body.Close()return []model.ProjectAuthor{}, err}resp.Body.Close()Defer closing the body immediately after creation of fd[1]
resp, err := client.Do(getReq)[1] https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body
@ -139,0 +166,4 @@fmt.Printf("project.go: could not fetch member with URL %s due to %s\n", author.Uri, err)return nil, err}return io.ReadAll(resp.Body)Response's body not closed anywhere!! Possible resource leak.