[SOLVED] Avoid N-square perf with recursive comments


#1

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:

<div>
					  {{ 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>

</div>
<span>
{{ $.context.body | safeHTML }}<br/>
</span>
{{ 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/>
</div>
{{ end }}

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


#2

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