Optimize some of the tight loops in the web playlist renderer

- rewrite DB lookups to use raw SQL
- get rid of some of the redundant template rendering
- unfold some of the deeply nested templates