diff --git a/backend/app/rest/api/rest_public.go b/backend/app/rest/api/rest_public.go index 11573c5e..cbfa6c74 100644 --- a/backend/app/rest/api/rest_public.go +++ b/backend/app/rest/api/rest_public.go @@ -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 } diff --git a/backend/app/rest/tree.go b/backend/app/rest/tree.go index bccf0a21..58152217 100644 --- a/backend/app/rest/tree.go +++ b/backend/app/rest/tree.go @@ -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) diff --git a/backend/app/store/engine/bolt_accessor.go b/backend/app/store/engine/bolt_accessor.go index fc3099a4..dfe64cf1 100644 --- a/backend/app/store/engine/bolt_accessor.go +++ b/backend/app/store/engine/bolt_accessor.go @@ -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 }