]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Document performance optimizations 00/2500/4
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 28 Nov 2018 06:42:22 +0000 (08:42 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 30 Nov 2018 22:04:11 +0000 (00:04 +0200)
gitlab #217

Change-Id: Ia61baca7ab92f73d10ddc87456aca1575795e80e

bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java

index ec65027ec0ad50994fb1116eddaa1c02e731c906..73c510317314e6937c4688ce5407c7146dd73081 100644 (file)
@@ -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);
                }
 
index 6ec2e6734a5a70808dcb02d6ef9e05c43a3a97ef..4915fc002ecdbc91b0a54806f796daa8f730b85e 100644 (file)
@@ -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<List<String>> {
+
+        protected DocumentPropertyKeys(Resource resource) {
+            super(resource);
+        }
 
         @Override
-        public Collection<String> getKeys(ReadGraph graph, Variable context) throws DatabaseException {
-            
+        public List<String> perform(ReadGraph graph) throws DatabaseException {
+
+            List<String> result = new ArrayList<>();
+
             DocumentationResource DOC = DocumentationResource.getInstance(graph);
-            StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
-            Map<String, Variable> 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<String> getKeys(ReadGraph graph, Variable parent) throws DatabaseException {
+
+            if(parent instanceof StandardProceduralChildVariable) {
+
+                StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent;
+                List<String> 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<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
-            return ps.get(key).getValue(graph);
-            
+            return context.getPropertyValue(graph, key);
         }
-        
+
     }
     
     public static DocumentProperties primitiveProperties() throws DatabaseException {
index 7d1af5f4c1ea6d765811c036986a96a08ba2736a..dce4b34ab44e46c7d28ef70b3902b0663ea4fbe6 100644 (file)
@@ -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);