I'm developing a CI project that needs to outputs a perfect binary tree in HTML. Each node in the tree relates to a record in a table. The table currently has upwards of 10 million rows and I'm going to need to output a tree with depth of at least 9, so things could get slow quickly if it's not built optimally.
Using the CI's MVC paradigm, what's the best way to organize this data? With such a large table, I don't want to have to hit the database too many times, and building a tree like this can get costly very quickly (# cells = 2^(depth+1)-1).
So far I've built the controller to handle the request (easy part) and a library to handle/build the tree structure by recursively hitting the DB and creating an object for each node. I'm sorta stuck on how to organize the rest. Should I handle the tree traversal and HTML output from within a view/helper? If we do that, there's going to be a whole bunch of logic in the view(s) which I know people try to avoid. Similarly, I know it's looked down upon to output any HTML from within a library but given this structure it almost seems like it's logical to handle all the recursion/output from there.
Any advice would be very helpful, and thanks in advance!