clean code duplication in find control

This commit is contained in:
Umputun
2018-01-07 19:52:13 -06:00
parent 539a3c46bc
commit 1c696f5a38
+8 -15
View File
@@ -238,26 +238,19 @@ func (s *Server) findCommentsCtrl(w http.ResponseWriter, r *http.Request) {
}
comments = s.mod.maskBlockedUsers(comments)
if r.URL.Query().Get("format") == "tree" {
treeComments := format.MakeTree(comments, r.URL.Query().Get("sort"))
b, err := encodeJSONWithHTML(treeComments)
if err != nil {
common.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't encode comments")
return
}
s.respCache.Set(cacheKey, b, time.Hour)
renderJSONFromBytes(w, r, b)
return
var bdata []byte
switch r.URL.Query().Get("format") {
case "tree":
bdata, err = encodeJSONWithHTML(format.MakeTree(comments, r.URL.Query().Get("sort")))
default:
bdata, err = encodeJSONWithHTML(comments)
}
b, err := encodeJSONWithHTML(comments)
if err != nil {
common.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't encode comments")
return
}
s.respCache.Set(cacheKey, b, time.Hour)
renderJSONFromBytes(w, r, b)
s.respCache.Set(cacheKey, bdata, time.Hour)
renderJSONFromBytes(w, r, bdata)
}
// GET /last/{max}?site=siteID - last comments for the siteID, across all posts, sorted by time