dataloader
dataloader copied to clipboard
[BUG] batchScheduleFn is always called even if value taken from cache
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
why is this behavior a bug?
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.
@travigd exactly