changeset 2089:bbd6816d9e9e

big optimization on effect editing. 50% time still in rebuildSettingsFromGraph though, and the rest is in setLabel
author drewp@bigasterisk.com
date Sun, 29 May 2022 02:54:57 -0700
parents 0617b6006ec4
children cb7556869244
files light9/web/live/Effect.ts light9/web/live/GraphToControls.ts light9/web/live/Light9DeviceControl.ts light9/web/live/Light9LiveControls.ts
diffstat 4 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/live/Effect.ts	Sun May 29 02:53:46 2022 -0700
+++ b/light9/web/live/Effect.ts	Sun May 29 02:54:57 2022 -0700
@@ -1,7 +1,7 @@
 import debug from "debug";
 import { Literal, NamedNode, Quad_Object, Quad_Predicate, Quad_Subject, Term } from "n3";
 import { some } from "underscore";
-import { Patch } from "../patch";
+import { Patch, patchContainsPreds } from "../patch";
 import { SyncedGraph } from "../SyncedGraph";
 
 type Color = string;
@@ -56,14 +56,19 @@
     this.graph.applyAndSendPatch(patch);
   }
 
-  rebuildSettingsFromGraph() {
+  rebuildSettingsFromGraph(patch?: Patch) {
     const U = this.graph.U();
-    log("syncFromGraph", this.uri);
+    if (patch && !patchContainsPreds(patch, [U(":setting"), U(":device"), U(":deviceAttr")])) {
+      // that's an approx list of preds , but it just means we'll miss some pathological settings edits
+    //   return;
+    }
+
+    // log("syncFromGraph", this.uri);
 
     const newSettings = [];
 
     for (let setting of Array.from(this.graph.objects(this.uri, U(":setting")))) {
-      log(`  setting ${setting.value}`);
+      //   log(`  setting ${setting.value}`);
       if (!isUri(setting)) throw new Error();
       let value: ControlValue;
       const device = this.graph.uriValue(setting, U(":device"));
@@ -82,7 +87,7 @@
           value = this.graph.stringValue(setting, pred); // this may find multi values and throw
         }
       }
-      log(`change: graph contains ${deviceAttr.value} ${value}`);
+    //   log(`change: graph contains ${deviceAttr.value} ${value}`);
 
       newSettings.push({ device, deviceAttr, setting, value });
     }
@@ -90,6 +95,7 @@
     log(`rebuild to ${this.settings.length}`);
     this.onValuesChanged();
   }
+
   currentValue(device: NamedNode, deviceAttr: NamedNode): ControlValue | null {
     for (let s of this.settings) {
       if (device.equals(s.device) && deviceAttr.equals(s.deviceAttr)) {
@@ -98,6 +104,7 @@
     }
     return null;
   }
+
   // change this object now, but return the patch to be applied to the graph so it can be coalesced.
   edit(device: NamedNode, deviceAttr: NamedNode, newValue: ControlValue | null): Patch {
     log(`edit: value=${newValue}`);
--- a/light9/web/live/GraphToControls.ts	Sun May 29 02:53:46 2022 -0700
+++ b/light9/web/live/GraphToControls.ts	Sun May 29 02:54:57 2022 -0700
@@ -6,7 +6,7 @@
 
 type NewValueCb = (newValue: ControlValue | null) => void;
 
-// More efficient bridge between liveControl widgets and graph edits,
+// More efficient bridge between liveControl widgets and graph edits (inside Effect),
 // as opposed to letting each widget scan the graph and push lots of
 // tiny patches to it.
 export class GraphToControls {
--- a/light9/web/live/Light9DeviceControl.ts	Sun May 29 02:53:46 2022 -0700
+++ b/light9/web/live/Light9DeviceControl.ts	Sun May 29 02:54:57 2022 -0700
@@ -146,7 +146,7 @@
 
   syncDeviceAttrsFromGraph(patch?: Patch) {
     const U = this.graph.U();
-    if (patch != null && !patchContainsPreds(patch, [U("rdf:type"), U(":deviceAttr"), U(":dataType"), U(":choice")])) {
+    if (patch && !patchContainsPreds(patch, [U("rdf:type"), U(":deviceAttr"), U(":dataType"), U(":choice")])) {
       return;
     }
     try {
--- a/light9/web/live/Light9LiveControls.ts	Sun May 29 02:53:46 2022 -0700
+++ b/light9/web/live/Light9LiveControls.ts	Sun May 29 02:54:57 2022 -0700
@@ -3,7 +3,7 @@
 import { customElement, property } from "lit/decorators.js";
 import { NamedNode } from "n3";
 import { sortBy, uniq } from "underscore";
-import { Patch } from "../patch";
+import { Patch, patchContainsPreds } from "../patch";
 import { getTopGraph } from "../RdfdbSyncedGraph";
 import { SyncedGraph } from "../SyncedGraph";
 import { GraphToControls } from "./GraphToControls";
@@ -90,6 +90,9 @@
 
   findDevices(patch?: Patch) {
     const U = this.graph.U();
+    if (patch && !patchContainsPreds(patch, [U("rdf:type")])) {
+      return;
+    }
 
     this.devices = [];
     let classes = this.graph.subjects(U("rdf:type"), U(":DeviceClass"));