instead of recursion, you can use the path_ids method or something like, it would drop from n+1 queries into 2(or so)