Load profiles last notes asynchronously

This commit is contained in:
Daniele Tonon
2023-12-20 07:50:17 +01:00
parent c3c9e3d08d
commit 6a2ff72985
6 changed files with 84 additions and 40 deletions

View File

@@ -23,6 +23,12 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
isRSS = true
}
isLastNotes := false
if strings.HasPrefix(code, "profile-last-notes") {
code = code[19:]
isLastNotes = true
}
data, err := grabData(r.Context(), code, isSitemap)
if err != nil {
w.Header().Set("Cache-Control", "max-age=60")
@@ -35,10 +41,6 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
return
}
if len(data.renderableLastNotes) != 0 {
w.Header().Set("Cache-Control", "max-age=3600")
}
if isSitemap {
w.Header().Add("content-type", "text/xml")
w.Header().Set("Cache-Control", "max-age=86400")
@@ -60,6 +62,14 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) {
Metadata: data.metadata,
LastNotes: data.renderableLastNotes,
})
} else if isLastNotes {
w.Header().Add("content-type", "text/html")
if len(data.renderableLastNotes) != 0 {
w.Header().Set("Cache-Control", "max-age=3600")
}
LastNotesTemplate.Render(w, &LastNotesPage{
LastNotes: data.renderableLastNotes,
})
} else {
w.Header().Add("content-type", "text/html")
w.Header().Set("Cache-Control", "max-age=86400")