PlanetScale

Performant database tree traversal with Rails

Jul 12, 2023Mike Coutermarsh
Performant database tree traversal with Rails
SummaryAI, from the source post

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.

More from the Database Branching and Blue/Green Deployments trail