Entities performance improvement in RelationshipServiceImpl

If there's no max on the relationships, don't bother trying to verify whether the max would be exceeded
Don't get virtual metadata for retrieving the relationship type
This commit is contained in:
Ben Bosman
2021-01-26 15:04:15 +01:00
parent 12ffc78452
commit fa90057203
2 changed files with 10 additions and 5 deletions

View File

@@ -244,6 +244,10 @@ public class RelationshipServiceImpl implements RelationshipService {
Integer maxCardinality,
RelationshipType relationshipType,
boolean isLeft) throws SQLException {
if (maxCardinality == null) {
//no need to check the relationships
return true;
}
List<Relationship> rightRelationships = findByItemAndRelationshipType(context, itemToProcess, relationshipType,
isLeft);
if (maxCardinality != null && rightRelationships.size() >= maxCardinality) {
@@ -253,7 +257,8 @@ public class RelationshipServiceImpl implements RelationshipService {
}
private boolean verifyEntityTypes(Item itemToProcess, EntityType entityTypeToProcess) {
List<MetadataValue> list = itemService.getMetadata(itemToProcess, "relationship", "type", null, Item.ANY);
List<MetadataValue> list = itemService.getMetadata(itemToProcess, "relationship", "type",
null, Item.ANY, false);
if (list.isEmpty()) {
return false;
}

View File

@@ -227,8 +227,8 @@ public class RelationshipServiceImplTest {
when(metsList.get(0).getValue()).thenReturn("Entitylabel");
when(relationshipService
.findByItemAndRelationshipType(context, leftItem, testRel, true)).thenReturn(leftTypelist);
when(itemService.getMetadata(leftItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
when(itemService.getMetadata(rightItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
when(itemService.getMetadata(leftItem, "relationship", "type", null, Item.ANY, false)).thenReturn(metsList);
when(itemService.getMetadata(rightItem, "relationship", "type", null, Item.ANY, false)).thenReturn(metsList);
when(relationshipDAO.create(any(), any())).thenReturn(relationship);
// The reported Relationship should match our defined relationship
@@ -305,8 +305,8 @@ public class RelationshipServiceImplTest {
relationship = getRelationship(leftItem, rightItem, testRel, 0,0);
// Mock the state of objects utilized in update() to meet the success criteria of the invocation
when(itemService.getMetadata(leftItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
when(itemService.getMetadata(rightItem, "relationship", "type", null, Item.ANY)).thenReturn(metsList);
when(itemService.getMetadata(leftItem, "relationship", "type", null, Item.ANY, false)).thenReturn(metsList);
when(itemService.getMetadata(rightItem, "relationship", "type", null, Item.ANY, false)).thenReturn(metsList);
when(authorizeService.authorizeActionBoolean(context, relationship.getLeftItem(),
Constants.WRITE)).thenReturn(true);