Performant database tree traversal with Rails
14-Jul-2023 716
We recently solved an interesting performance problem in our Rails API when performing a tree traversal.We have some code that figures out a 3-way merge for your database schemas. To do this, we need to calculate a merge base between two schemas (like git!).Our Rails API keeps track of changes to each PlanetScale database schema. We call each of these changes a "schema snapshot," similar to a git commit that stores the state of the schema at a specific time. Each snapshot can have one or two parents. When merging branches, we perform a breadth-first search on the history of each change until we find the common ancestor between both branches. This is the merge base.
Performant database tree traversal with Rails #ruby #rubydeveloper #rubyonrails #Performant #database #traversal #Rails #database https://rubyonrails.ba/link/performant-database-tree-traversal-with-rails