# HG changeset patch # User drewp@bigasterisk.com # Date 2022-05-29 09:54:57 # Node ID bbd6816d9e9e1c1413a63821f22ea0d296b25c85 # Parent 0617b6006ec4573ed1163b3549cfc357c633e515 big optimization on effect editing. 50% time still in rebuildSettingsFromGraph though, and the rest is in setLabel diff --git a/light9/web/live/Effect.ts b/light9/web/live/Effect.ts --- a/light9/web/live/Effect.ts +++ b/light9/web/live/Effect.ts @@ -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 @@ 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}`); diff --git a/light9/web/live/GraphToControls.ts b/light9/web/live/GraphToControls.ts --- a/light9/web/live/GraphToControls.ts +++ b/light9/web/live/GraphToControls.ts @@ -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 { diff --git a/light9/web/live/Light9DeviceControl.ts b/light9/web/live/Light9DeviceControl.ts --- a/light9/web/live/Light9DeviceControl.ts +++ b/light9/web/live/Light9DeviceControl.ts @@ -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 { diff --git a/light9/web/live/Light9LiveControls.ts b/light9/web/live/Light9LiveControls.ts --- a/light9/web/live/Light9LiveControls.ts +++ b/light9/web/live/Light9LiveControls.ts @@ -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"));