Browse Source

mol-plugin: do not recompute query if the parent structure hasn't changed

David Sehnal 6 years ago
parent
commit
bb12275b26
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/mol-plugin/state/transforms/model.ts

+ 12 - 0
src/mol-plugin/state/transforms/model.ts

@@ -264,6 +264,7 @@ const StructureSelection = PluginStateTransform.BuiltIn({
     apply({ a, params, cache }) {
         const compiled = compile<Sel>(params.query);
         (cache as { compiled: QueryFn<Sel> }).compiled = compiled;
+        (cache as { source: Structure }).source = a.data;
 
         const result = compiled(new QueryContext(a.data));
         const s = Sel.unionStructure(result);
@@ -274,6 +275,11 @@ const StructureSelection = PluginStateTransform.BuiltIn({
     update: ({ a, b, oldParams, newParams, cache }) => {
         if (oldParams.query !== newParams.query) return StateTransformer.UpdateResult.Recreate;
 
+        if ((cache as { source: Structure }).source === a.data) {
+            return StateTransformer.UpdateResult.Unchanged;
+        }
+        (cache as { source: Structure }).source === a.data;
+
         if (updateStructureFromQuery((cache as { compiled: QueryFn<Sel> }).compiled, a.data, b, newParams.label)) {
             return StateTransformer.UpdateResult.Updated;
         }
@@ -298,6 +304,7 @@ const UserStructureSelection = PluginStateTransform.BuiltIn({
         const query = transpileMolScript(parsed[0]);
         const compiled = compile<Sel>(query);
         (cache as { compiled: QueryFn<Sel> }).compiled = compiled;
+        (cache as { source: Structure }).source = a.data;
         const result = compiled(new QueryContext(a.data));
         const s = Sel.unionStructure(result);
         const props = { label: `${params.label || 'Selection'}`, description: structureDesc(s) };
@@ -308,6 +315,11 @@ const UserStructureSelection = PluginStateTransform.BuiltIn({
             return StateTransformer.UpdateResult.Recreate;
         }
 
+        if ((cache as { source: Structure }).source === a.data) {
+            return StateTransformer.UpdateResult.Unchanged;
+        }
+        (cache as { source: Structure }).source === a.data;
+
         updateStructureFromQuery((cache as { compiled: QueryFn<Sel> }).compiled, a.data, b, newParams.label);
         return StateTransformer.UpdateResult.Updated;
     }