{"repo":"exAspArk/batch-loader","free":true,"listed":false,"github":"https://github.com/exAspArk/batch-loader","clone":"git clone https://github.com/exAspArk/batch-loader.git","description":":zap: Powerful tool for avoiding N+1 DB or HTTP queries","language":"Ruby","stars":1124,"topics":["n-plus-1","batching","ruby","gem","graphql","graphql-ruby","dataloader","nplus1"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"BatchLoader This gem provides a generic lazy batching mechanism to avoid N+1 DB queries, HTTP queries, etc. Developers from these companies use BatchLoader : Contents Highlights Usage Why? Basic example How it works RESTful API example GraphQL example Loading multiple items Batch key Caching Replacing methods Installation API Related tools Implementation details Development Contributing Alternatives License Code of Conduct Highlights Generic utility to avoid N+1 DB queries, HTTP requests, etc. Adapted Ruby implementation of battle-tested tools like Haskell Haxl, JS DataLoader, etc. Batching is isolated and lazy, load data in batch where and when it's needed. Automatically caches previous queries (identity map). Thread-safe ( loader ). No need to share batching through variables or custom defined classes. No dependencies, no monkey-patches, no extra primitives such as Promises. Usage Why? Let's have a look at the code with N+1 queries: The naive approach would be to preload dependent objects on the top level: But the problem here is that load posts now depends on the child association and knows that it has to preload data for future use. And it'll do it every time, even if it's not necessary. Can we do better? Sure! Basic example With BatchLoader we can rewrite the code above: As we can see, batching is isolated and described right in a place where it's needed. How it works In general, BatchLoader returns a lazy object. Each lazy object knows which data it needs to load and ho","default_branch":null,"files":null,"tree":[],"storefront":"/r/exAspArk","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/exAspArk/batch-loader/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}