Changeset - bbd6816d9e9e
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 3 years ago 2022-05-29 09:54:57
drewp@bigasterisk.com
big optimization on effect editing. 50% time still in rebuildSettingsFromGraph though, and the rest is in setLabel
4 files changed with 18 insertions and 8 deletions:
0 comments (0 inline, 0 general)
light9/web/live/Effect.ts
Show inline comments
 
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 @@ export class Effect {
 
    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 @@ export class Effect {
 
          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 @@ export class Effect {
 
    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 @@ export class Effect {
 
    }
 
    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}`);
light9/web/live/GraphToControls.ts
Show inline comments
 
@@ -6,7 +6,7 @@ const log = debug("g2c");
 

	
 
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 {
light9/web/live/Light9DeviceControl.ts
Show inline comments
 
@@ -146,7 +146,7 @@ export class Light9DeviceControl extends
 

	
 
  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 {
light9/web/live/Light9LiveControls.ts
Show inline comments
 
@@ -3,7 +3,7 @@ import { css, html, LitElement, Property
 
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 @@ export class Light9LiveControls extends 
 

	
 
  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"));
0 comments (0 inline, 0 general)