forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'datahub-project:master' into master
- Loading branch information
Showing
215 changed files
with
159,796 additions
and
2,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/LazyDataLoaderRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.linkedin.datahub.graphql; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.dataloader.DataLoader; | ||
import org.dataloader.DataLoaderRegistry; | ||
|
||
/** | ||
* The purpose of this class is to avoid loading 42+ dataLoaders when many of the graphql queries do | ||
* not use all of them. | ||
*/ | ||
@Slf4j | ||
public class LazyDataLoaderRegistry extends DataLoaderRegistry { | ||
private final QueryContext queryContext; | ||
private final Map<String, Function<QueryContext, DataLoader<?, ?>>> dataLoaderSuppliers; | ||
|
||
public LazyDataLoaderRegistry( | ||
QueryContext queryContext, | ||
Map<String, Function<QueryContext, DataLoader<?, ?>>> dataLoaderSuppliers) { | ||
super(); | ||
this.queryContext = queryContext; | ||
this.dataLoaderSuppliers = new ConcurrentHashMap<>(dataLoaderSuppliers); | ||
} | ||
|
||
@Override | ||
public <K, V> DataLoader<K, V> getDataLoader(String key) { | ||
return super.computeIfAbsent( | ||
key, | ||
k -> { | ||
Function<QueryContext, DataLoader<?, ?>> supplier = dataLoaderSuppliers.get(key); | ||
if (supplier == null) { | ||
throw new IllegalArgumentException("No DataLoader registered for key: " + key); | ||
} | ||
return supplier.apply(queryContext); | ||
}); | ||
} | ||
|
||
@Override | ||
public Set<String> getKeys() { | ||
return Stream.concat(dataLoaders.keySet().stream(), dataLoaderSuppliers.keySet().stream()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
@Override | ||
public DataLoaderRegistry combine(DataLoaderRegistry registry) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.