Coder Social home page Coder Social logo

"Prime" items about batch-loader HOT 3 CLOSED

exaspark avatar exaspark commented on July 21, 2024
"Prime" items

from batch-loader.

Comments (3)

 avatar commented on July 21, 2024

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.

exAspArk avatar exAspArk commented on July 21, 2024

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.

 avatar commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.