Skip to content
Snippets Groups Projects
Commit bb12275b authored by David Sehnal's avatar David Sehnal
Browse files

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

parent ab8c6b5f
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment