From: Antti Villberg Date: Wed, 28 Nov 2018 06:42:22 +0000 (+0200) Subject: Document performance optimizations X-Git-Tag: v1.43.0~136^2~248 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d9fee21e1ff594dfbaa51a0597b4695f289aa29d;p=simantics%2Fplatform.git Document performance optimizations gitlab #217 Change-Id: Ia61baca7ab92f73d10ddc87456aca1575795e80e --- diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java index ec65027ec..73c510317 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java @@ -305,8 +305,7 @@ public class DocumentServerUtils { @Override public JSONObject perform(ReadGraph graph) throws DatabaseException { - DocumentationResource DOC = DocumentationResource.getInstance(graph); - DocumentProperties properties = variable.getPropertyValue(graph, DOC.Properties_primitiveProperties); + DocumentProperties properties = variable.getPropertyValue(graph, "primitiveProperties"); return computeStatic(graph, variable, properties); } diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 6ec2e6734..4915fc002 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -23,8 +23,10 @@ import org.simantics.db.Session; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.common.primitiverequest.Adapter; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.BinaryRead; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.Logger; @@ -212,28 +214,91 @@ public class Functions { }; - static class StandardDocumentProperties implements DocumentProperties { + static class DocumentPropertyKeys extends ResourceRead> { + + protected DocumentPropertyKeys(Resource resource) { + super(resource); + } @Override - public Collection getKeys(ReadGraph graph, Variable context) throws DatabaseException { - + public List perform(ReadGraph graph) throws DatabaseException { + + List result = new ArrayList<>(); + DocumentationResource DOC = DocumentationResource.getInstance(graph); - StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties); - Map ps = primitiveProperties.getVariables(graph, asd, null); - return ps.keySet(); - + + if(graph.hasStatement(resource, DOC.Properties_commands)) + result.add("commands"); + if(graph.hasStatement(resource, DOC.Properties_dataDefinitions)) + result.add("dataDefinitions"); + + DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); + DirectStatements ds = dqs.getDirectPersistentStatements(graph, resource); + + for(Statement stm : ds) { + + Resource predicate = stm.getPredicate(); + PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + + if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { + result.add(info.name); + } else { + Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation); + if(definition != null) { + PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); + result.add(info2.name); + } + } + } + + return result; + + } + + } + + static class StandardDocumentProperties implements DocumentProperties { + + @Override + public Collection getKeys(ReadGraph graph, Variable parent) throws DatabaseException { + + if(parent instanceof StandardProceduralChildVariable) { + + StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent; + List result = new ArrayList<>(); + for(Variable property : procedural.getProperties(graph)) { + if(property instanceof StandardAssertedGraphPropertyVariable) { + StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property; + if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) { + result.add(ass.property.name); + } + continue; + } + Resource predicate = property.getPossiblePredicateResource(graph); + if(predicate != null) { + PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { + result.add(info.name); + } + } + } + + return result; + + } else { + + Resource parentRes = parent.getRepresents(graph); + return graph.syncRequest(new DocumentPropertyKeys(parentRes), TransientCacheAsyncListener.instance()); + + } + } @Override public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException { - - DocumentationResource DOC = DocumentationResource.getInstance(graph); - StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties); - Map ps = primitiveProperties.getVariables(graph, asd, null); - return ps.get(key).getValue(graph); - + return context.getPropertyValue(graph, key); } - + } public static DocumentProperties primitiveProperties() throws DatabaseException { diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index 7d1af5f4c..dce4b34ab 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -103,7 +103,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< Resource root = graph.syncRequest(new IndexRoot(doc)); return Pair.make(componentType, root); } else { - System.err.println("component = " + component); + //System.err.println("component = " + component); Resource root = graph.syncRequest(new IndexRoot(component)); // Resource componentType = graph.getSingleType(doc); return Pair.make(null, root);