Actually improved template perf.

Previous performance patch has turned out bogus as it accidentally
caused the template to skip populating the sidebar with links.

This, OTOH, caches the right post ids for the sidebar before
template parsing to avoid repeated list traversal. The build time
reduction is closer to 45% rather than the 60% as mistakenly
reported before.