Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #297
sonnenhaft opened this issue Jun 14, 2020 · 3 comments
Open
Tracked by #297
Labels

Comments

@sonnenhaft
Copy link

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 sonnenhaft added the bug label Jun 14, 2020
@CreatCodeBuild
Copy link

why is this behavior a bug?

@twavv
Copy link

twavv commented Sep 6, 2020

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.

@CreatCodeBuild
Copy link

@travigd exactly

@saihaj saihaj mentioned this issue Mar 11, 2022
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants