Skip to content

Commit

Permalink
blob handling is too slow #235
Browse files Browse the repository at this point in the history
  • Loading branch information
abstratt committed Sep 6, 2017
1 parent 5c4b2a8 commit 17a0b34
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -108,16 +109,15 @@ else if (validRelationships.containsKey(slotName)) {
simpleInstanceLinkingActions.add(new LinkingAction(relationship, instanceNode, slotName));
}
}

Instance created = repository.createInstance(newInstance);
simpleLinkingActions.put(created, simpleInstanceLinkingActions);
multipleLinkingActions.put(created, multipleInstanceLinkingActions);
getEntityInstances(entity.getEntityNamespace(), entity.getName()).add(created.getObjectId());
if (!blobActions.isEmpty()) {
blobActions.forEach(action -> action.accept(created));
repository.updateInstance(created);
blobActions.clear();
}

getEntityInstances(entity.getEntityNamespace(), entity.getName()).add(created.getObjectId());
multipleLinkingActions.put(created, multipleInstanceLinkingActions);
simpleLinkingActions.put(created, simpleInstanceLinkingActions);
return created;
}

Expand Down Expand Up @@ -229,15 +229,11 @@ private void setProperty(Instance newInstance, JsonNode propertyValue, DataEleme
break;
case START_OBJECT:
if (property.getTypeRef().getKind() == TypeKind.Blob) {
Map<String, Object> asMap = new LinkedHashMap<>();
String contentType = propertyValue.get("contentType").asText();
String originalName = Optional.ofNullable(propertyValue.get("originalName")).map(it -> it.asText()).orElse(null);
asMap.put("contentType", contentType);
asMap.put("originalName", originalName);
value = asMap;
blobActions.add(new BlobAction(property.getName(), propertyValue.get("contents").asText(), contentType, propertyValue.get("originalName").asText()));
blobActions.add(new BlobAction(property.getName(), propertyValue.get("contents").asText(), contentType, originalName));
value = null;
}

break;
}
newInstance.setValue(property.getName(), value);
Expand Down Expand Up @@ -289,10 +285,9 @@ class BlobAction extends DelayedAction {
@Override
public void accept(Instance instance) {
Blob blob = repository.createBlob(instance.getTypeRef(), instance.getObjectId(), slotName, contentType, originalName);
instance.setValue(slotName, blob.toMap());
repository.updateInstance(instance);
byte[] asBytes = Base64.getDecoder().decode(contents);
repository.writeBlob(instance.getTypeRef(), instance.getObjectId(), slotName, blob.getToken(), new ByteArrayInputStream(asBytes));
LogUtils.debug(ID, () -> instance.getReference().toString() + blob.toMap().toString());
}
}

Expand Down

1 comment on commit 17a0b34

@abstratt
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.