Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Add Override annotations and comment why we optimize.

See #4612
Original pull request: #4613
  • Loading branch information
mp911de committed Apr 11, 2024
1 parent e239745 commit 37dae78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Iterable<Document> apply(MongoCollection<Document> collection) {

/**
* @return a {@link DocumentReferenceQuery} that will not match any documents.
* @since 4.3
* @since 4.2.5
*/
static DocumentReferenceQuery forNoResult() {
return NoResultsFilter.INSTANCE;
Expand All @@ -139,8 +139,8 @@ static DocumentReferenceQuery forNoResult() {

/**
* A dedicated {@link DocumentReferenceQuery} that will not match any documents.
*
* @since 4.3
*
* @since 4.2.5
*/
enum NoResultsFilter implements DocumentReferenceQuery {
INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ ValueProvider valueProviderFor(Object source) {

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

Object target = source instanceof DocumentReferenceSource documentReferenceSource ? documentReferenceSource.getTargetSource()
Object target = source instanceof DocumentReferenceSource documentReferenceSource
? documentReferenceSource.getTargetSource()
: source;

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

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

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

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

if(ObjectUtils.isEmpty(value)) {
if (ObjectUtils.isEmpty(value)) {
return DocumentReferenceQuery.forNoResult();
}

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

@Override
public Document getQuery() {
return query;
}
Expand Down

0 comments on commit 37dae78

Please sign in to comment.