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 Details

    • QueryBatchLoader

      public QueryBatchLoader(String db, String collection)
  • Method Details

    • setMongoClient

      public static void setMongoClient(com.mongodb.MongoClient mClient)
    • load

      public CompletionStage<List<org.bson.BsonValue>> load(List<org.bson.BsonValue> queries)
      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:
      load in interface org.dataloader.BatchLoader<org.bson.BsonValue,​org.bson.BsonValue>
      Parameters:
      queries - : list of queries to merge by $or operator