From b8fec2e96c157acbf26b7828c336dfb47dd5d7fb Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Feb 2011 19:17:44 +0000 Subject: [PATCH] NIHVIVO-2038 Improve performance of creating grouped property list by keeping a list of object property uris to check against, so a property doesn't have to be instantiated from the propertyUri in order to check whether it's on the list. --- .../individual/GroupedPropertyList.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index ebf339280..57a74d549 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -141,14 +141,23 @@ public class GroupedPropertyList extends BaseTemplateModel { } private void mergeAllPossibleObjectProperties(List objectPropertyList, List propertyList) { + + // Performance improvement: keep a list of uris on the propertyList to check against, rather than + // having to instantiate a property from propertyUri to check against the propertyList. + List propertyListUris = new ArrayList(propertyList.size()); + for (Property p : propertyList) { + propertyListUris.add(p.getURI()); + } + PropertyInstanceDao piDao = wdf.getPropertyInstanceDao(); Collection allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI()); + if (allPropInstColl != null) { ObjectPropertyDao opDao = wdf.getObjectPropertyDao(); for (PropertyInstance pi : allPropInstColl) { if (pi != null) { if (! alreadyOnObjectPropertyList(objectPropertyList, pi)) { - addIfNotAlreadyOnList(propertyList, pi.getPropertyURI(), opDao); + addIfNotAlreadyOnList(propertyList, propertyListUris, pi.getPropertyURI(), opDao); } } else { log.error("a property instance in the Collection created by PropertyInstanceDao.getAllPossiblePropInstForIndividual() is unexpectedly null"); @@ -158,23 +167,26 @@ public class GroupedPropertyList extends BaseTemplateModel { // In future, vitro ns props will be phased out. Vitro public properties should be changed so they do no // constitute a special case. for (String propertyUri : VITRO_PROPS_TO_ADD_TO_LIST) { - addIfNotAlreadyOnList(propertyList, propertyUri, opDao); + addIfNotAlreadyOnList(propertyList, propertyListUris, propertyUri, opDao); } } else { log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()"); } } - private void addIfNotAlreadyOnList(List propertyList, String propertyUri, ObjectPropertyDao opDao) { + private void addIfNotAlreadyOnList(List propertyList, List propertyListUris, String propertyUri, ObjectPropertyDao opDao) { - ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri); - if (op == null) { - log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()"); - } else if (op.getURI() == null) { - log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()"); - } else if (! alreadyOnPropertyList(propertyList, op)) { - propertyList.add(op); - } + if ( ! propertyListUris.contains(propertyUri)) { + ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri); + if (op == null) { + log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()"); + } else if (op.getURI() == null) { + log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()"); + } else { + propertyList.add(op); + propertyListUris.add(propertyUri); + } + } } protected void mergeAllPossibleDataProperties(List propertyList) { @@ -186,7 +198,6 @@ public class GroupedPropertyList extends BaseTemplateModel { if (dp.getURI() == null) { log.error("DataProperty dp returned with null propertyURI from dpDao.getAllPossibleDatapropsForIndividual()"); } else if (! alreadyOnPropertyList(propertyList, dp)) { - //dp.setLabel(dp.getPublicName()); propertyList.add(dp); } } else {