<pre>
def get_all_children(self, node):
    stack = [node]
    visited = set(node)
    while stack:
        node = stack.pop()
        for child in self.cached_relations[node]:
            if child in visited:
                continue
            yield child
            visited.add(node)
            stack.push(child)
</pre>