dataloader icon indicating copy to clipboard operation
dataloader copied to clipboard

[BUG] batchScheduleFn is always called even if value taken from cache

Open sonnenhaft opened this issue 5 years ago • 3 comments

Expected Behavior

"batchScheduleFn" should not get called when value is taken from cache

Current Behavior

"batchScheduleFn" is called always and delaying response

Possible Solution

after checking if value is in cache - to ignore "batchScheduleFn"

Steps to Reproduce

Console log in "batchScheduleFn", it is called always

sonnenhaft avatar Jun 14 '20 17:06 sonnenhaft

why is this behavior a bug?

CreatCodeBuild avatar Jun 17 '20 20:06 CreatCodeBuild

This isn't (from my perspective) a bug. It helps synchronize execution.

Suppose you have a function

function getFriends(userId) {
  const user = userLoader.load(userId);
  const friends = userLoader.loadMany(user.friendIds);
  return friends;
}

Suppose foo is already in the DataLoader cache, and we call

const fooFriends = getFriends("foo");
const barFriends = getFriends("bar");
console.log(Promise.all([fooFriends, barFriends]));

We actually WANT the call to userLoader.load("foo") to be scheduled with the next batch, so that the two .loadMany calls are synchronized.

twavv avatar Sep 06 '20 00:09 twavv

@travigd exactly

CreatCodeBuild avatar Sep 13 '20 15:09 CreatCodeBuild