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 OSS projects

Contact us

We’d love to hear from you! We’re not really all that evil, and we love discussing potential projects, intriguing ideas, and new opportunities. Complete the form below or drop us a line at surrender@evilmartians.com.

Martians at a glance
16
years in business

A product development consultancy that works with startups and established businesses, while also creating open source-based products and services