Performant database tree traversal with Rails
Jul 12, 2023Mike Coutermarsh

Summary
This post addresses a performance bottleneck in the Rails API related to tree traversal for calculating database schema merge bases. The N+1 query problem was solved by introducing an in-memory cache (`SnapshotMergeBaseCache`) to store schema snapshots and preloading recent snapshots for each branch to reduce database round trips. The post also briefly discusses alternative solutions like database recursive CTEs and the materialized path technique.