A Ruby gem that automatically eager loads ActiveRecord associations to prevent N+1 queries without manual configuration.
Goldiloader is a Ruby gem for Rails applications that automatically eager loads ActiveRecord associations to prevent N+1 query problems. It monitors when associations are accessed and batches database queries to load data for all relevant models at once, reducing manual eager loading configuration.
Rails developers working with ActiveRecord who want to eliminate N+1 queries without manually specifying `includes` or `preload` in every query.
It automatically optimizes database queries by eager loading associations on-demand, reducing boilerplate code and preventing performance issues from N+1 queries without changing existing application logic.
Just the right amount of Rails eager loading
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Goldiloader automatically batches database queries when associations are first accessed, eliminating manual `includes` calls—demonstrated in the README where posts for five blogs load in a single query instead of five separate ones.
Supports disabling automatic eager loading globally, per-thread, per-query, or per-association, giving developers granular control over when to apply optimizations without refactoring code.
Enables custom preload logic via the `goldiload` method for aggregations, external API calls, or non-standard data sources, extending beyond ActiveRecord's native eager loading capabilities.
Works with arbitrary nesting of associations across models, ensuring deep relationships are optimized automatically without additional configuration or manual intervention.
Cannot auto-eager load associations using `limit`, `offset`, or `finder_sql` options, requiring complex workarounds like lateral joins that increase code complexity and maintenance overhead.
For `has_one` associations that depend on SQL limits, auto-eager loading fetches all related records instead of one, potentially causing severe performance degradation with large datasets, as warned in the README.
Moving from older versions (e.g., 0.x or 1.x) requires syntax updates, such as replacing `auto_include` association options with query scope methods, which can break existing code and increase migration effort.