at a minimum i think this function should build a tree that contains only IDs and then work off that tree. the cost of building that tree on every request might still be unmanageable, though and require significant thought to optimize (maybe we can cache it per domain)