Skip to content

Commit

Permalink
SED-1024 SED-1028 Improving performance of import/export and find usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromecomte committed May 26, 2022
1 parent b3ef280 commit 424bcd9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected Document migrateArtefactToPlan(AtomicInteger successCount, AtomicInteg

Document plan = new Document();

plan.put(AbstractIdentifiableObject.ID, artefactIdToPlanId.get(t.getId()));
plan.put(AbstractIdentifiableObject.ID, artefactIdToPlanId.get(t.getId().toString()));
plan.put("attributes", attributes);
plan.put("root", migrateArtefact(t));
plan.put("visible", visiblePlan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class EntityDependencyTreeVisitor {
private static final Logger logger = LoggerFactory.getLogger(EntityDependencyTreeVisitor.class);
private final EntityManager entityManager;
private final ObjectPredicate objectPredicate;
private final Map<Class<?>, BeanInfo> beanInfoCache = new ConcurrentHashMap<>();
// Declared as static for performance reasons. In the current implementation, this class gets instantiated quite often
// TODO declare it as non-static to avoid potential leaks
private static final Map<Class<?>, BeanInfo> beanInfoCache = new ConcurrentHashMap<>();

public EntityDependencyTreeVisitor(EntityManager entityManager, ObjectPredicate objectPredicate) {
super();
Expand Down
20 changes: 9 additions & 11 deletions step-core/src/main/java/step/core/imports/ImportContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
******************************************************************************/
package step.core.imports;

import ch.exense.commons.io.FileHelper;
import step.core.Version;
import step.core.collections.CollectionFactory;
import step.core.collections.inmemory.InMemoryCollectionFactory;
import step.resources.LocalResourceManagerImpl;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import step.core.collections.filesystem.FilesystemCollectionFactory;
import ch.exense.commons.io.FileHelper;
import step.core.Version;
import step.resources.LocalResourceManagerImpl;

public class ImportContext implements AutoCloseable {

private final ImportConfiguration importConfiguration;
Expand All @@ -40,8 +41,7 @@ public class ImportContext implements AutoCloseable {
private final File workFolder;
private final LocalResourceManagerImpl localResourceMgr;

private final File tempWorkspace;
private final FilesystemCollectionFactory tempCollectionFactory;
private final CollectionFactory tempCollectionFactory;

private final Map<String, String> references = new HashMap<String, String>();
private final Map<String, String> newToOldReferences = new HashMap<String, String>();
Expand All @@ -51,8 +51,7 @@ public ImportContext(ImportConfiguration importConfiguration) throws IOException
super();
this.importConfiguration = importConfiguration;

tempWorkspace = FileHelper.createTempFolder();
tempCollectionFactory = new FilesystemCollectionFactory(tempWorkspace);
tempCollectionFactory = new InMemoryCollectionFactory(null);
workFolder = FileHelper.createTempFolder("step-import");
localResourceMgr = new LocalResourceManagerImpl(workFolder);
}
Expand Down Expand Up @@ -81,7 +80,7 @@ public LocalResourceManagerImpl getLocalResourceMgr() {
return localResourceMgr;
}

public FilesystemCollectionFactory getTempCollectionFactory() {
public CollectionFactory getTempCollectionFactory() {
return tempCollectionFactory;
}

Expand All @@ -108,6 +107,5 @@ public File getWorkFolder() {
@Override
public void close() throws Exception {
FileHelper.deleteFolder(workFolder);
FileHelper.deleteFolder(tempWorkspace);
}
}
6 changes: 3 additions & 3 deletions step-core/src/main/java/step/core/imports/ImportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import step.core.accessors.Accessor;
import step.core.accessors.DefaultJacksonMapperProvider;
import step.core.collections.Collection;
import step.core.collections.CollectionFactory;
import step.core.collections.Document;
import step.core.collections.Filters;
import step.core.collections.filesystem.FilesystemCollectionFactory;
import step.core.entities.Entity;
import step.core.entities.EntityManager;
import step.migration.MigrationManager;
Expand Down Expand Up @@ -124,7 +124,7 @@ public ImportResult importAll(ImportConfiguration importConfig) throws Exception

private void importEntitiesFromTemporaryCollection(ImportConfiguration importConfig, ImportContext importContext, List<String> entityNames) {
// Perform migration tasks on temporary collections
final FilesystemCollectionFactory tempCollectionFactory = importContext.getTempCollectionFactory();
final CollectionFactory tempCollectionFactory = importContext.getTempCollectionFactory();
migrationManager.migrate(tempCollectionFactory, importContext.getVersion(), Version.getCurrentVersion());

// Replace IDs of all entities if overwriting is disabled
Expand Down Expand Up @@ -172,7 +172,7 @@ private String importEntitiesToTemporaryCollection(ImportConfiguration importCon
Entity<?, ?> entityByName = entityManager.getEntityByName(name);
boolean skip = skipEntityType(importConfig.getEntitiesFilter(), name);

FilesystemCollectionFactory tempCollectionFactory = importContext.getTempCollectionFactory();
CollectionFactory tempCollectionFactory = importContext.getTempCollectionFactory();
Collection<Document> tempCollection = tempCollectionFactory.getCollection(name, Document.class);

if (entityByName == null) {
Expand Down

0 comments on commit 424bcd9

Please sign in to comment.