Polishing.

Reduce allocations by reusing IndexDefinition in RemoveIndexedData.

Tweak test method name.

See #2882
Original pull request: #2895
This commit is contained in:
Mark Paluch
2024-04-19 08:16:59 +02:00
parent 8afabc1fe3
commit 2f34f63e28
4 changed files with 12 additions and 21 deletions

View File

@@ -210,24 +210,14 @@ public class PathIndexResolver implements IndexResolver {
}
Object transformedValue = indexDefinition.valueTransformer().convert(value);
IndexedData indexedData;
IndexedData indexedData = null;
if (transformedValue == null) {
indexedData = new RemoveIndexedData(new IndexedData() {
@Override
public String getIndexName() {
return indexDefinition.getIndexName();
}
@Override
public String getKeyspace() {
return indexDefinition.getKeyspace();
}
});
indexedData = new RemoveIndexedData(indexDefinition);
} else {
indexedData = indexedDataFactoryProvider.getIndexedDataFactory(indexDefinition).createIndexedDataFor(value);
}
data.add(indexedData);
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.core.convert;
import org.springframework.data.redis.core.index.IndexDefinition;
/**
* {@link RemoveIndexedData} represents a removed index entry from a secondary index for a property path in a given keyspace.
*
@@ -23,21 +25,20 @@ package org.springframework.data.redis.core.convert;
*/
public class RemoveIndexedData implements IndexedData {
private final IndexedData delegate;
private final IndexDefinition indexDefinition;
RemoveIndexedData(IndexedData delegate) {
super();
this.delegate = delegate;
RemoveIndexedData(IndexDefinition indexDefinition) {
this.indexDefinition = indexDefinition;
}
@Override
public String getIndexName() {
return delegate.getIndexName();
return indexDefinition.getIndexName();
}
@Override
public String getKeyspace() {
return delegate.getKeyspace();
return indexDefinition.getKeyspace();
}
@Override

View File

@@ -24,7 +24,7 @@ import org.springframework.util.ObjectUtils;
/**
* {@link IndexDefinition} allow to set up a blueprint for creating secondary index structures in Redis. Setting up
* conditions allows to define {@link Condition} that have to be passed in order to add a value to the index. This
* allows to fine grained tune the index structure. {@link IndexValueTransformer} gets applied to the raw value for
* allows to fine-grained tune the index structure. {@link IndexValueTransformer} gets applied to the raw value for
* creating the actual index entry.
*
* @author Christoph Strobl