Skip to content

Commit

Permalink
#250 optimize collection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
aburmeis committed Aug 23, 2023
1 parent ef0a287 commit aa938a2
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import com.arangodb.springframework.core.util.MetadataUtils;
import com.arangodb.util.MapBuilder;
import com.arangodb.velocypack.VPackSlice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
Expand All @@ -72,6 +74,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
Expand All @@ -97,6 +100,7 @@ public class ArangoTemplate implements ArangoOperations, CollectionCallback, App
private static final String REPSERT_QUERY = "LET doc = @doc " + REPSERT_QUERY_BODY;
private static final String REPSERT_MANY_QUERY = "FOR doc IN @docs " + REPSERT_QUERY_BODY;

private static final Logger LOGGER = LoggerFactory.getLogger(ArangoTemplate.class);
private static final SpelExpressionParser PARSER = new SpelExpressionParser();

private volatile ArangoDBVersion version;
Expand Down Expand Up @@ -190,7 +194,9 @@ private ArangoCollection _collection(final String name, final ArangoPersistentEn
final ArangoCollection collection = value.getCollection();
if (persistentEntity != null && !entities.contains(entityClass)) {
value.addEntityClass(entityClass);
if (!transactional) {
if (transactional) {
LOGGER.debug("Not ensuring any indexes of collection {} for {} during transaction", collection.name(), entityClass);
} else {
ensureCollectionIndexes(collection(collection), persistentEntity);
}
}
Expand Down Expand Up @@ -761,11 +767,12 @@ public CollectionOperations collection(final Class<?> entityClass) throws DataAc

@Override
public CollectionOperations collection(String name) throws DataAccessException {
ArangoPersistentEntity<?> persistentEntity = converter.getMappingContext().getPersistentEntities().stream()
.filter(e -> name.equals(e.getCollection()))
.findAny()
.orElse(null);
return collection(_collection(name, persistentEntity, persistentEntity == null ? new CollectionCreateOptions() : persistentEntity.getCollectionOptions(), false));
List<ArangoCollection> collections = converter.getMappingContext().getPersistentEntities().stream()
.filter(persistentEntity -> name.equals(persistentEntity.getCollection()))
.map(persistentEntity -> _collection(name, persistentEntity, persistentEntity.getCollectionOptions(), false))
.collect(Collectors.toList());
ArangoCollection result = collections.isEmpty() ? _collection(name, null, null, false) : collections.get(0);
return collection(result);
}

@Override
Expand Down

0 comments on commit aa938a2

Please sign in to comment.