[SOLVED] Avoid N-square perf with recursive comments


I have a website where I am considering using the data collections in order to hold comments.
I would love to support hierarchical comments, but I am stuck with N-square at best and I have a few posts that would kill it.
This is the partial that renders the comments, which is recursive:

					  {{ if $.context.gravatar }}
			  <img src="https://www.gravatar.com/avatar/{{ $.context.gravatar }}?s=20" />
			  {{ end }}
<span><b>{{ $.context.author }}</b></span> - <span style="font-size:12px">{{ dateFormat "Monday, Jan 2, 2006 - 3:04 PM" $.context.date }}</span>

{{ $.context.body | safeHTML }}<br/>
{{ range where $.allComments "parent" $.parentId }}
<div style="padding-left:15px;border-left: 2px;border-left-color:black;border-left-style:solid">
   {{ partial "single_comment" (dict "allComments" $.allComments "parentId" .id "context" .) }} <br/>
{{ end }}

It would be nice to be able to create a map on the fly, but I couldn’t figure out how.


I was able to solve this by using (.Scratch.Add .parent (slice .)) which did the trick.