borinquenkid commented on code in PR #16820:
URL: https://github.com/apache/grails-core/pull/16820#discussion_r4437022513


##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy:
##########
@@ -1118,6 +1124,22 @@ abstract class AbstractDetachedCriteria<T> implements 
Criteria, Cloneable {
         this.with(criteria)
     }
 
+    /**
+     * Returns this criteria with its deferred query applied, without mutating 
it: the original keeps the
+     * deferred query, so a criteria shared between threads materializes a 
copy each time and no deferred
+     * definition is applied twice.
+     */
+    AbstractDetachedCriteria<T> materializeLazyCriteria() {
+        Closure pending = lazyQuery
+        if (pending == null) {
+            return this
+        }
+        AbstractDetachedCriteria<T> materialized = clone()

Review Comment:
   Addressed in e9e562667f. `clone()` now copies every 
`DetachedAssociationCriteria` node, including nested ones, through 
`copyAssociationCriteria`, so the copy's criteria list and its association map 
share one new node per association, and that node keeps its alias. 
`DetachedAssociationCriteria.newInstance()` keeps the node type on copy. A 
deferred `createAlias()` or a chained `.eq(...)` applied to a materialized copy 
therefore never reaches the original. The new clone-isolation features in 
`DetachedCriteriaCloneSpec` cover shared nodes, nested nodes, and a deferred 
closure that mutates a node.



-- 
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