[VIVO-1031] Improve logged in performance by handling a bulk of faux properties statements at once, rather than one-by-one.
This commit is contained in:
parent
4883621236
commit
15cd6a8ac0
11 changed files with 87 additions and 67 deletions
|
@ -109,6 +109,7 @@ public interface Individual extends ResourceBean, Comparable<Individual> {
|
|||
* This is crap. It was put in so IndividualFiltering could filter object properties properly,
|
||||
* but what we really need is either: filters have a reference to a webappDaoFactory, or
|
||||
* all ObjectPropertyStatements are resolved when they are created. See VIVO-946 and VIVO-984.
|
||||
* @param list
|
||||
*/
|
||||
void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt);
|
||||
void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list);
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
|||
}
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
// No webappDaoFactory, so nothing to do.
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,6 @@ public interface ObjectPropertyStatementDao {
|
|||
* If that is so, then set the domain and range (and the domainURI and
|
||||
* rangeURI) of the property of this statement to match the faux property.
|
||||
*/
|
||||
void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt);
|
||||
void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
|
@ -185,9 +184,7 @@ public class IndividualFiltering implements Individual {
|
|||
if (opStmts == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for(ObjectPropertyStatement opStmt: opStmts) {
|
||||
_innerIndividual.resolveAsFauxPropertyStatement(opStmt);
|
||||
}
|
||||
_innerIndividual.resolveAsFauxPropertyStatements(opStmts);
|
||||
ArrayList<ObjectPropertyStatement> filtered = new ArrayList<ObjectPropertyStatement>();
|
||||
Filter.filter(opStmts, _filters.getObjectPropertyStatementFilter(), filtered);
|
||||
return filtered;
|
||||
|
@ -563,8 +560,8 @@ public class IndividualFiltering implements Individual {
|
|||
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
_innerIndividual.resolveAsFauxPropertyStatement(stmt);
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
_innerIndividual.resolveAsFauxPropertyStatements(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,9 +37,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
|||
|
||||
private List<ObjectPropertyStatement> filterAndWrapList(List<ObjectPropertyStatement> list){
|
||||
if( ( list ) != null ){
|
||||
for (ObjectPropertyStatement stmt: list) {
|
||||
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatement(stmt);
|
||||
}
|
||||
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatements(list);
|
||||
|
||||
ArrayList<ObjectPropertyStatement> ctemp = new ArrayList<ObjectPropertyStatement>();
|
||||
Filter.filter(list,filters.getObjectPropertyStatementFilter(),ctemp);
|
||||
|
@ -142,8 +140,8 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
|||
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatement(stmt);
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
innerObjectPropertyStatementDao.resolveAsFauxPropertyStatements(list);
|
||||
}
|
||||
|
||||
}
|
|
@ -99,12 +99,12 @@ public class FauxPropertyDaoJena extends JenaBaseDao implements FauxPropertyDao
|
|||
|
||||
@Override
|
||||
public List<FauxProperty> getFauxPropertiesForBaseUri(String uri) {
|
||||
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||
if (uri == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> contextUris = new ArrayList<>();
|
||||
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||
Set<String> contextUris = new HashSet<>();
|
||||
ResIterator contextResources = displayModel
|
||||
.listSubjectsWithProperty(CONFIG_CONTEXT_FOR,
|
||||
createResource(uri));
|
||||
|
@ -131,11 +131,11 @@ public class FauxPropertyDaoJena extends JenaBaseDao implements FauxPropertyDao
|
|||
*/
|
||||
@Override
|
||||
public FauxProperty getFauxPropertyFromContextUri(String contextUri) {
|
||||
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||
if (contextUri == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||
OntResource context = displayModel.createOntResource(contextUri);
|
||||
if (!displayModel.contains(context, RDF.type, CONFIG_CONTEXT)) {
|
||||
log.debug("'" + contextUri + "' is not a CONFIG_CONTEXT");
|
||||
|
@ -634,5 +634,4 @@ public class FauxPropertyDaoJena extends JenaBaseDao implements FauxPropertyDao
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -618,8 +618,8 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatement(stmt);
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatements(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1088,8 +1088,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatement(stmt);
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
webappDaoFactory.getObjectPropertyStatementDao().resolveAsFauxPropertyStatements(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -559,45 +559,70 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
|||
* accordingly.
|
||||
*/
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
if (stmt == null) {
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, List<FauxProperty>> fauxPropMap = new HashMap<String, List<FauxProperty>>();
|
||||
Map<String, List<VClass>> subjectTypeMap = new HashMap<String, List<VClass>>();
|
||||
Map<String, List<VClass>> objectTypeMap = new HashMap<String, List<VClass>>();
|
||||
|
||||
for (ObjectPropertyStatement stmt : list) {
|
||||
ObjectProperty prop = obtainObjectPropertyFromStatement(stmt);
|
||||
if (prop == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<FauxProperty> fauxProps = getWebappDaoFactory()
|
||||
if (prop != null) {
|
||||
List<FauxProperty> fauxProps = fauxPropMap.get(prop.getURI());
|
||||
if (fauxProps == null) {
|
||||
fauxProps = getWebappDaoFactory()
|
||||
.getFauxPropertyDao()
|
||||
.getFauxPropertiesForBaseUri(prop.getURI());
|
||||
if (fauxProps.isEmpty()) {
|
||||
return;
|
||||
|
||||
fauxPropMap.put(prop.getURI(), fauxProps);
|
||||
}
|
||||
|
||||
if (fauxProps != null && !fauxProps.isEmpty()) {
|
||||
List<VClass> subjectTypes = null;
|
||||
List<VClass> objectTypes = null;
|
||||
|
||||
if (stmt.getSubjectURI() != null) {
|
||||
subjectTypes = subjectTypeMap.get(stmt.getSubjectURI());
|
||||
}
|
||||
|
||||
if (stmt.getObjectURI() != null) {
|
||||
objectTypes = objectTypeMap.get(stmt.getObjectURI());
|
||||
}
|
||||
|
||||
if (subjectTypes == null) {
|
||||
Individual subject = obtainSubjectFromStatement(stmt);
|
||||
if (subject == null) {
|
||||
return;
|
||||
if (subject != null) {
|
||||
subjectTypes = subject.getVClasses();
|
||||
subjectTypeMap.put(stmt.getSubjectURI(), subjectTypes);
|
||||
}
|
||||
}
|
||||
|
||||
if (objectTypes == null) {
|
||||
Individual object = obtainObjectFromStatement(stmt);
|
||||
if (object == null) {
|
||||
return;
|
||||
if (object != null) {
|
||||
objectTypes = object.getVClasses();
|
||||
objectTypeMap.put(stmt.getObjectURI(), objectTypes);
|
||||
}
|
||||
}
|
||||
|
||||
List<VClass> subjectTypes = subject.getVClasses();
|
||||
List<VClass> objectTypes = object.getVClasses();
|
||||
if (subjectTypes != null && objectTypes != null) {
|
||||
for (FauxProperty fauxProp : fauxProps) {
|
||||
VClass subjectType = selectType(subjectTypes,
|
||||
fauxProp.getDomainURI());
|
||||
VClass subjectType = selectType(subjectTypes, fauxProp.getDomainURI());
|
||||
VClass objectType = selectType(objectTypes, fauxProp.getRangeURI());
|
||||
|
||||
if (subjectType != null && objectType != null) {
|
||||
prop.setDomainVClass(subjectType);
|
||||
prop.setDomainVClassURI(subjectType.getURI());
|
||||
prop.setRangeVClass(objectType);
|
||||
prop.setRangeVClassURI(objectType.getURI());
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ public class IndividualStub implements Individual {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
// Nothing to do: no associated webappDaoFactory
|
||||
}
|
||||
|
||||
|
|
|
@ -231,9 +231,9 @@ public class ObjectPropertyStatementDaoStub implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void resolveAsFauxPropertyStatement(ObjectPropertyStatement stmt) {
|
||||
public void resolveAsFauxPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
throw new RuntimeException(
|
||||
"ObjectPropertyStatementDaoStub.resolveAsFauxPropertyStatement() not implemented.");
|
||||
"ObjectPropertyStatementDaoStub.resolveAsFauxPropertyStatements() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue