rishabhdaim commented on code in PR #858:
URL: https://github.com/apache/jackrabbit-oak/pull/858#discussion_r1129366551


##########
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java:
##########
@@ -486,4 +489,55 @@ default int getNodeNameLimit() {
     default Throttler throttler() {
         return NO_THROTTLING;
     }
+
+    /**
+     * Get a list of documents with only projected fields (as mentioned in 
projections param)
+     * along with "_id" field and where the key is greater than a start value 
and
+     * less than an end value <em>and</em> the given "indexed property" is 
greater
+     * or equals the specified value.
+     * <p>
+     * The indexed property can either be a {@link Long} value, in which case 
numeric
+     * comparison applies, or a {@link Boolean} value, in which case "false" 
is mapped
+     * to "0" and "true" is mapped to "1".
+     * <p>
+     * The returned documents are sorted by key and are immutable.
+     *
+     * @param <T> the document type
+     * @param collection the collection
+     * @param fromKey the start value (excluding)
+     * @param toKey the end value (excluding)
+     * @param indexedProperty the name of the indexed property (optional)
+     * @param startValue the minimum value of the indexed property
+     * @param limit the maximum number of entries to return
+     * @param projection {@link List} of projected keys (optional). Keep this 
empty to fetch all fields on document.
+     * @return the list (possibly empty)
+     * @throws DocumentStoreException if the operation failed. E.g. because of
+     *          an I/O error.
+     */
+    @NotNull
+    default <T extends Document> List<T> query(final Collection<T> collection,
+                                               final String fromKey,
+                                               final String toKey,
+                                               final String indexedProperty,
+                                               final long startValue,
+                                               final int limit,
+                                               final List<String> projection) 
throws DocumentStoreException {
+
+        final List<T> list = query(collection, fromKey, toKey, 
indexedProperty, startValue, limit);
+
+        if (projection == null || projection.isEmpty()) {
+            list.forEach(Document::seal);
+            return list;
+        }
+
+        final Set<String> projectedSet = newHashSet(projection);
+        projectedSet.add(ID);
+
+        list.forEach(t -> {
+            t.unSeal();
+            t.keySet().retainAll(projectedSet);
+            t.seal();
+        });

Review Comment:
   Yes, I agree this would modify the documents coming from the cache.
   
   I will fix this by cloning the document and then returning the cloned 
document with projected fields only.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to