enforec empty list of comments on nil response

This commit is contained in:
Umputun
2019-01-25 22:49:52 -06:00
parent 6250f2e52e
commit f7de26ef4b
3 changed files with 7 additions and 2 deletions
+3
View File
@@ -38,6 +38,9 @@ func (s *Rest) findCommentsCtrl(w http.ResponseWriter, r *http.Request) {
switch r.URL.Query().Get("format") {
case "tree":
tree := rest.MakeTree(maskedComments, sort, s.ReadOnlyAge)
if tree.Nodes == nil { // eliminate json nil serialization
tree.Nodes = []*rest.Node{}
}
if s.DataService.IsReadOnly(locator) {
tree.Info.ReadOnly = true
}
+2 -2
View File
@@ -111,8 +111,8 @@ func (t *Tree) proc(comments []store.Comment, node *Node, rd *recurData, parentI
}
// filter returns comments for parentID
func (t *Tree) filter(comments []store.Comment, fn func(comment store.Comment) bool) (f []store.Comment) {
func (t *Tree) filter(comments []store.Comment, fn func(comment store.Comment) bool) []store.Comment {
f := []store.Comment{}
for _, c := range comments {
if fn(c) {
f = append(f, c)
@@ -170,6 +170,8 @@ func (b *BoltDB) Find(locator store.Locator, sortFld string) (comments []store.C
// Last returns up to max last comments for given siteID
func (b *BoltDB) Last(siteID string, max int) (comments []store.Comment, err error) {
comments = []store.Comment{}
if max > lastLimit || max == 0 {
max = lastLimit
}