[Group Hierarchy] Implement and test the hierarchy iterator
Problem: When caching and collecting all the descendant ids for a given group in a background job, we might face the issue where the hierarchy is so large that our traversal_ids
based hierarchy queries could run into timeout.
To address this problem, we need to implement an iterator that walks through the group hierarchy efficiently. There was some research related to the problem here: https://docs.gitlab.com/ee/development/database/poc_tree_iterator.html
Task: tidy up the PoC implementation and put it into a helper class. Cover it with test cases.
The PoC implementation can be found here: !134499 (diffs)
Ideas:
- Split the longer methods.
- Avoid hardcoding table names, use the
quoted_table_name
method. - Use AR or Arel instead of raw queries.
Edited by Adam Hegyi