]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java
Use query caching previous to multi-query-thread to retain performance
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / CodeGen.java
index 2f14b98a54cf6725adc148cc49d623973711bb20..8661428cb6b94349a034a095bb6e33c56365dc40 100644 (file)
@@ -47,6 +47,13 @@ public class CodeGen {
                line(content, "    QueryCache cache  = graph.processor.cache;");
                if(shortcut) {
                        line(content, "    if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature[1] + ")) {");
+                       line(content, "        if (SINGLE) {");
+                       line(content, "            " + clazz + " e = cache.peek" + clazz + "(" + signature[1] + ");");
+                       line(content, "            if (e != null && e.isReady()) {");
+                       line(content, "                " + (genReturn ? "return " : "") + "e.performFromCache(graph, procedure);");
+                       if(!genReturn) line(content, "                return;");
+                       line(content, "            }");
+                       line(content, "        }");
                        line(content, "        " + (genReturn ? "return " : "") + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);");
                        if(!genReturn) line(content, "        return;");
                        line(content, "    }");
@@ -65,6 +72,14 @@ public class CodeGen {
                line(content, "}");
                line(content, "");
 
+        String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
+
+               line(content, "private " + clazz + " peek" + clazz + "(" + signature[0] + ") {");
+               line(content, "    synchronized(" + lower +"Map) {");
+               line(content, "        return (" + clazz + ") " + lower + "Map.get(" + signature[1] + ");");
+               line(content, "    }");
+               line(content, "}");
+               line(content, "");
        }
 
        public void generateRemove(StringBuilder content, String clazz, String[] signature) {
@@ -144,6 +159,10 @@ public class CodeGen {
 
                                        content.append("public class QueryCache extends QueryCacheBase {\n");
                                        content.append("\n");
+                                       
+                                       line(content, "private static final boolean SINGLE = true;");
+                                       content.append("\n");
+                                       
                                        line(content,"public QueryCache(QuerySupport querySupport, int threads) {");
                                        line(content,"    super(querySupport, threads);");
                                        line(content,"}");