Giter Site home page Giter Site logo

Comments (5)

ThisIsMissEm avatar ThisIsMissEm commented on May 3, 2024

It'd seem so; I think the docs probably need to be updated.

from dataloader.

leebyron avatar leebyron commented on May 3, 2024

I just made some updates to Readme that hopefully improve this. Your suggestion is half-correct. If the entire batch request fails, then cache is cleared. If individual values are provided Error, those are cached. I updated the language to make this clear.

from dataloader.

luckydrq avatar luckydrq commented on May 3, 2024

Thanks, i got your point.

However, in real world from what i see, it rarely happens when individual values are provided Error, because batch function is designed to reduce network cost of fetching data to backend. For example, a batch function to load data from a rational database may look like this:

var batchFn = ids => {
  return new Promise((resolve, reject) => {
    sqlRun(`SELECT * FROM user_table WHERE ID IN (${ids.join(',')})`, (err, records) => {
      if (err) {
        return reject(err);
      } else {
        return resolve(records);
      }
    });  
  });
};

rather than

var batchFn = ids => {
  return Promise.all(ids.map(id => {
    return new Promise((resolve, reject) => {
      sqlRun(`SELECT * FROM user_table WHERE id=${id}`, (err, record) => {
        if (err) {
          return reject(err);
        } else {
          return resolve(record);
        }
      });
    });
  }));
}

from dataloader.

leebyron avatar leebyron commented on May 3, 2024

It certainly depends on the system you're communicating with, and of course it's up to how you implement your batching function. There is of course the case where the batch itself fails, which is well illustrated by your first example. There is also a case where your batch function may return a combination of values and errors. That is - the batch load itself succeeded however some of the individual operations within the batch failed.

from dataloader.

luckydrq avatar luckydrq commented on May 3, 2024

Agreed, just to share my thoughts, thanks!

from 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.