Skip to content

Commit 49a3be6

Browse files
committed
Polishing.
Add Override annotations and comment why we optimize. See #4612 Original pull request: #4613
1 parent dd9f0bc commit 49a3be6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReferenceLoader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public Iterable<Document> apply(MongoCollection<Document> collection) {
130130

131131
/**
132132
* @return a {@link DocumentReferenceQuery} that will not match any documents.
133-
* @since 4.3
133+
* @since 4.2.5
134134
*/
135135
static DocumentReferenceQuery forNoResult() {
136136
return NoResultsFilter.INSTANCE;
@@ -139,8 +139,8 @@ static DocumentReferenceQuery forNoResult() {
139139

140140
/**
141141
* A dedicated {@link DocumentReferenceQuery} that will not match any documents.
142-
*
143-
* @since 4.3
142+
*
143+
* @since 4.2.5
144144
*/
145145
enum NoResultsFilter implements DocumentReferenceQuery {
146146
INSTANCE;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReferenceLookupDelegate.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ ValueProvider valueProviderFor(Object source) {
240240

241241
EvaluationContext evaluationContextFor(MongoPersistentProperty property, Object source, SpELContext spELContext) {
242242

243-
Object target = source instanceof DocumentReferenceSource documentReferenceSource ? documentReferenceSource.getTargetSource()
243+
Object target = source instanceof DocumentReferenceSource documentReferenceSource
244+
? documentReferenceSource.getTargetSource()
244245
: source;
245246

246247
if (target == null) {
@@ -285,6 +286,7 @@ DocumentReferenceQuery computeFilter(MongoPersistentProperty property, Object so
285286

286287
Collection<Object> objects = (Collection<Object>) value;
287288

289+
// optimization: bypass query if the collection pointing to the references is empty
288290
if (objects.isEmpty()) {
289291
return DocumentReferenceQuery.forNoResult();
290292
}
@@ -301,7 +303,7 @@ DocumentReferenceQuery computeFilter(MongoPersistentProperty property, Object so
301303

302304
if (property.isMap() && value instanceof Map) {
303305

304-
if(ObjectUtils.isEmpty(value)) {
306+
if (ObjectUtils.isEmpty(value)) {
305307
return DocumentReferenceQuery.forNoResult();
306308
}
307309

@@ -461,6 +463,7 @@ public Iterable<Document> restoreOrder(Iterable<Document> documents) {
461463
return target.stream().sorted((o1, o2) -> compareAgainstReferenceIndex(ors, o1, o2)).collect(Collectors.toList());
462464
}
463465

466+
@Override
464467
public Document getQuery() {
465468
return query;
466469
}

0 commit comments

Comments
 (0)