Make Group Export groups serialisation non-recursive
Currently when using GroupTreeSaver
to serialize and export group and it's children (subgroups) it uses recursive approach.
https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/import_export/group_tree_saver.rb#L29-36
def serialize(group, relations_tree)
group_tree = tree_saver.serialize(group, relations_tree)
group.children.each do |child|
group_tree['children'] ||= []
group_tree['children'] << serialize(child, relations_tree)
end
group_tree
rescue => e
@shared.error(e)
end
end
This approach makes it difficult to optimize serialization process in the future (streaming approach using .ndjson
format).
@ayufan made a good suggestion to use iterative approach instead of a recursive one.
build an enumerator, and add them to the queue of items to serialize
I believe we can have single SQL query to get the group and all subgroups in one go
serialize the content of the enumerator
this ends-up nicely in ndjson
as it is flat list of small objects
then each group can have their own json of sub relations to serialize, or use json