fix/slow-page-load-due-to-authors-info-requests #14

Merged
aniram merged 9 commits from fix/slow-page-load-due-to-authors-info-requests into feature/fetch-projects-by-keyword 2026-02-04 19:19:59 +00:00
Owner
No description provided.
aniram self-assigned this 2026-02-01 19:46:40 +00:00
aniram added this to the 2026.1 milestone 2026-02-01 19:46:51 +00:00
aniram left a comment
Author
Owner

few changes needed, more caution with correct placement of call to close HTTP response body stream.

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 {
Author
Owner

Remove unused struct

Remove unused struct
aniram marked this conversation as resolved
@ -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") }
Author
Owner

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

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
aniram marked this conversation as resolved
@ -133,0 +103,4 @@
p.CIDMainAuthor = mainAuthor
p.CIDMainAuthor.CIDMember = memberWrapper.Member
m.Unlock()
return err
Author
Owner

Should return nil

Should return nil
aniram marked this conversation as resolved
@ -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)
Author
Owner

Should print author instead of member

Should print **author** instead of member
aniram marked this conversation as resolved
@ -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)
Author
Owner

Should print author instead of member

Should print **author** instead of member
aniram marked this conversation as resolved
@ -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") }
Author
Owner

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

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
aniram marked this conversation as resolved
@ -131,1 +95,4 @@
fmt.Printf("project.go: could not marshal member due to %s\n", err)
return err
}
resp.Body.Close()
Author
Owner

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

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
aniram marked this conversation as resolved
@ -139,0 +144,4 @@
var authorsWrapper model.AuthorsWrapper
if 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()
Author
Owner

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

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
aniram marked this conversation as resolved
@ -139,0 +147,4 @@
resp.Body.Close()
return []model.ProjectAuthor{}, err
}
resp.Body.Close()
Author
Owner

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

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
aniram marked this conversation as resolved
@ -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)
Author
Owner

Response's body not closed anywhere!! Possible resource leak.

Response's body not closed anywhere!! Possible resource leak.
aniram marked this conversation as resolved
aniram merged commit 2f4787dcaf into feature/fetch-projects-by-keyword 2026-02-04 19:19:59 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aniram/cidadon!14
No description provided.