Skip to content

DataLoader as an interface - 3.x branch #62

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

Closed
wants to merge 3 commits into from
Closed

Conversation

bbakerman
Copy link
Member

This is the initial cut of a 3.x branch that will move DataLoader to an interface.

As it stands right now it's just the start of the refactor. There is more to come.

However I thought I would put it up progressively to show my work.

@bbakerman bbakerman changed the title DataLoader as an interface DataLoader as an interface - 3.x branch Mar 25, 2020
Copy link

@tinnou tinnou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks sensible to me!

/**
* Similar to {@link DataLoaderRegistry#dispatchAll()}, this calls {@link org.dataloader.DataLoader#dispatch()} on
* each of the registered {@link org.dataloader.DataLoader}s, but returns the number of dispatches.
* SThis calls {@link org.dataloader.DataLoader#dispatch()} on
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo This

@Internal
class DataLoaderHelper<K, V> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old Helper naming was a little confusing due to the class hierarchy, it makes much more sense now

stats.incrementLoadCount();

boolean batchingEnabled = loaderOptions.batchingEnabled();
boolean cachingEnabled = loaderOptions.cachingEnabled();

if (cachingEnabled) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that might be helpful to highlight here is the caching configuration flag now dictates whether values could be returned from the promise cache AND the value cache.

Since I can't think of a use case where someone would need the value cache but not the promise cache, I think we are good with having only one caching flag.

CompletableFuture<V> load(K key, Object loadContext) {
synchronized (dataLoader) {
Object cacheKey = getCacheKey(nonNull(key));
synchronized (this) {
Copy link

@tinnou tinnou Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say we have caching and batching disabled and the batchFunction happens to have some blocking code (not ideal). Having this entire block synchronized would cause to only have at most one batchFunction call executed per data loader instance, no?

Do you see any risk of contention when say resolving large lists (in GraphQL)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants