Comments (3)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
from batch-loader.
Hi @maletor,
Thank you for sharing the idea! I imagine the following scenario where it can be useful:
class Post
belongs_to :user
end
class User
belongs_to :avatar
end
class Avatar
end
def lazy_avatar(user)
BatchLoader.for(user.id).batch do |user_ids, loader|
Avatar.where(user_id: user_ids).each do |avatar|
loader.call(avatar.user_id, avatar)
end
end
end
def lazy_user(post)
BatchLoader.for(post.user_id).batch do |user_ids, loader|
User.where(id: user_ids).each do |user|
# ^ we could use User.where(...).includes(:avatar) to prime in this batch
loader.call(user.id, user)
end
end
end
Implementing the "prime" is possible. But the main challenge is to design a good API for developers. BatchLoader doesn't require developers to define and share the "loaders" (dataloader) or separate classes, everything lives in the block. It simplifies the usage but doesn't allow to share one BatchLoader reference in another.
from batch-loader.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
from batch-loader.
Related Issues (20)
- N+1 query problem with GraphQL (client side) HOT 6
- Possibility of deadlock HOT 2
- Extra computations for already loaded data happen when cache: false HOT 1
- How to get nested relation without n+1 on graphql ? HOT 4
- N+1 queries when batch loading has many association HOT 2
- Searchkick(elasticsearch) Object Associations HOT 2
- throwing undefined method `use' for BatchLoader::Middleware:Class HOT 4
- Using batch-loader to query a count of a has_many relation HOT 2
- batch-loader not working for non-nullable graphql fields, returns "Cannot return null for non-nullable field" HOT 14
- Warnings after updating to Ruby 2.7 HOT 3
- How I can filter associations values? HOT 2
- Wrong number of arguments (given 1, expected 0) HOT 6
- Loading across collections
- How to debug the code inside batch loader block HOT 1
- Erro on principal node is object
- BatchLoader::GraphQL with union type
- `BatchLoader.for().batch {}` evaluated as Truthy but should be Falsey HOT 5
- `BatchLoader::GraphQL.for` doesn't delegate missing methods as `BatchLoader.for` does
- Incompatibility with graphql-ruby 2.0.18+ HOT 2
- Why not to use `attr_accessor` for `batch_loader`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from batch-loader.