ArLazyPreload

Services & Skills

Share on

ArLazyPreload is a Ruby gem that brings association lazy load functionality to your Rails applications. There is a number of built-in methods to solve N+1 problem, but sometimes a list of associations to preload is not obvious—this is when you can get most of this gem.

  • Simple. The only thing you need to change is to use #lazy_preload instead of #includes, #eager_load or #preload.
  • Fast. Take a look at performance benchmark and memory benchmark.
  • Perfect fit for GraphQL. Define a list of associations to load at the top-level resolver and let the gem do its job.
  • Auto-preload support. If you don’t want to specify the association list, set ArLazyPreload.config.auto_preload to true.

Why should I use it?

Lazy loading is super helpful when the list of associations to load is determined dynamically. For instance, in GraphQL this list comes from the API client, and you’ll have to inspect the selection set to find out what associations are going to be used.

This gem uses a different approach: it won’t load anything until the association is called for the first time. When it happens, it loads all the associated records for all records from the initial relation in a single query.

Author

Further reading

In the same orbit

Explore more open source projects

Let's solve your hard problems

Martians at a glance
18
years in business

We're experts at helping developer products grow, with a proven track record in UI design, product iterations, cost-effective scaling, and much more. We'll lay out a strategy before our engineers and designers leap into action.

If you prefer email, write to us at surrender@evilmartians.com