Class QueryBatchLoader
java.lang.Object
org.restheart.graphql.dataloaders.QueryBatchLoader
- All Implemented Interfaces:
org.dataloader.BatchLoader<org.bson.BsonValue,org.bson.BsonValue>
public class QueryBatchLoader
extends Object
implements org.dataloader.BatchLoader<org.bson.BsonValue,org.bson.BsonValue>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCompletionStage<List<org.bson.BsonValue>>IDEA-1: each pair (db, collection) has its own batchLoader, so all their queries in the same "graph layer" are sent together in one request and their results are cached.static voidsetMongoClient(com.mongodb.MongoClient mClient)
-
Constructor Details
-
QueryBatchLoader
-
-
Method Details
-
setMongoClient
public static void setMongoClient(com.mongodb.MongoClient mClient) -
load
IDEA-1: each pair (db, collection) has its own batchLoader, so all their queries in the same "graph layer" are sent together in one request and their results are cached. PROBLEM: if we merge queries, by $or operator, we lose the correspondence query-result. IDEA-2: to solve the problem above, I used facet aggregation stage; It allows to create sub-pipelines, each one with its stages, and returns a document containing a pair (key, array), where the key is the name of sub-pipeline and the array contains results of the sub-pipeline. So, when in batch there at least 2 queries the aggregation pipeline is given by: - 1st Stage: {$match: {$or: [query1, query2, query3, ...]}} - 2nd Stage: {$facet: [ "0": [{$match: query1}, ...], "1": [{$match: query2}, ...], ... ]} PERFORMANCE: still to test...- Specified by:
loadin interfaceorg.dataloader.BatchLoader<org.bson.BsonValue,org.bson.BsonValue>- Parameters:
queries- : list of queries to merge by $or operator
-