I have a very slow ruby on rails page. It is displaying an hierarchical, unordered list. It was slow, because it was building the list through recursive SQL calls, which was stupid to start with. I've figured out how to get the SQL to give me the hierarchy. Now that I can get the required information through a single SQL call, I'm having issues building the resulting HTML.
This is what my SQL is returning. Each row is a different record, two columns 'id', and 'path'. I can easily break apart the different items by doing row.path.split
to get something like ['A', 'E', 'F']
. I just can't figure out the best way to manage the opening and closing tags of the list.
ID | PATH
01. Root | Root
02. A | Root A
03. B | Root B
04. C | Root B C
05. D | Root B D
06. E | Root A E
07. F | Root A E F
08. G | Root B D G
09. H | Root B C H
10. I | Root B D I
11. J | Root B D G J
12. F | Root B C H F
13. K | Root B D I K
14. L | Root B D I L
15. F | Root B D I L F
And I need the unordered list to look something like this: