Giter VIP home page Giter VIP logo

Comments (3)

bbakerman avatar bbakerman commented on June 3, 2024

Really what you are doing here is getting the "friends ids" of the character AND then loading those friends. So we need a batch loader that does those 2 operations at the same time.

So I think you might want to combine them into one batch loader that takes a "characterID" and can find friends for them all in the one step

So imagine your batch loader is like this (psudeo java code)

BatchLoader bl  = characterIdsKeys -> {
   
     ResultSet rs = db.execute(' select from friends where friends.characterId in ::characterIdsKeys:: group by friends.characterId');

   // now run through the group set of friends per characterId and make Character objects from them
  return serviceToUnpackGroupedResultSet(rs)
}

Now it might be that your database tables can only "find the ids of friends" in one query and then find the friends themselves via another query. So be it. Use 2 queries. Use the SQL "in" operator to find results for multiple elements (eg the batch of characters). Use SQL groupBy or order by to make sure you can pack back the results into a list that matches the input keys

from java-dataloader.

vincentlejeune avatar vincentlejeune commented on June 3, 2024

Hi @bbakerman

Thanks for your reply. I create a dataloader for the relation between characterId and the list of Friend. It works like a charm !

Just to be sure to understand, to load friends by characterIds, i create a dataloader that store the list of friends by characterId (DataLoader<CharacterId, List<Friend>>). So, by doing this, i by pass a potential Friend's dataloader (DataLoader<String, Friend>).

Is it possible to load the friends id and next use a Friend's dataloader to get the Friends, all of that in an async way ?

from java-dataloader.

budjb avatar budjb commented on June 3, 2024

This issue actually looks like the same thing I'm asking about in #36. @bbakerman, do you have an example of how the batch loader you pseudo-coded above would be used? This differs from the examples, since in the examples the IDs of the objects you want to load are passed to the dataloader, whereas here it seems you need to pass the ID of the source object. I'm not sure how that should look in usage.

from java-dataloader.

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.