From 59f5120521872029f89a7ac46c08954b123cd5bf Mon Sep 17 00:00:00 2001 From: sid597 Date: Wed, 22 Apr 2026 00:22:28 +0530 Subject: [PATCH] ENG-1664: Replace getBlockUidByTextOnPage scan with pull in settings writer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Datalog .q scan that resolved the top-level settings block on every write took ~318 ms per call on real graphs. Replaced with a hash-indexed roamAlphaAPI.pull by page title that walks :block/children — same pattern bulkReadSettings already uses. Behavior equivalence: the old query matched any descendant via :block/page; the new pull traverses direct :block/children only. Safe here because setBlockPropBasedSettings is only reached with keys[0] set to one of the three top-level settings keys (feature flags, global, personal user-id), all guaranteed to be direct children of the settings page. Measured on a real graph: BaseFlagPanel click handler 420 ms → 97 ms (−77%). The remaining 95 ms is refreshConfigTree > register translators, the inherent dual-read cost ENG-1616 flagged for post-ENG-1470 cleanup. --- .../src/components/settings/utils/accessors.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/roam/src/components/settings/utils/accessors.ts b/apps/roam/src/components/settings/utils/accessors.ts index 23407276d..a56951717 100644 --- a/apps/roam/src/components/settings/utils/accessors.ts +++ b/apps/roam/src/components/settings/utils/accessors.ts @@ -4,7 +4,6 @@ import getBlockProps, { } from "~/utils/getBlockProps"; import setBlockProps from "~/utils/setBlockProps"; import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid"; -import getBlockUidByTextOnPage from "roamjs-components/queries/getBlockUidByTextOnPage"; import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle"; import { getSubTree } from "roamjs-components/util"; import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree"; @@ -669,10 +668,17 @@ const setBlockPropBasedSettings = ({ return; } - const blockUid = getBlockUidByTextOnPage({ - text: keys[0], - title: DG_BLOCK_PROP_SETTINGS_PAGE_TITLE, - }); + const pageResult = window.roamAlphaAPI.pull( + "[{:block/children [:block/uid :block/string]}]", + [":node/title", DG_BLOCK_PROP_SETTINGS_PAGE_TITLE], + ) as Record | null; + const children = (pageResult?.[":block/children"] ?? []) as Record< + string, + json + >[]; + const match = children.find((child) => child[":block/string"] === keys[0]); + const matchedUid = match?.[":block/uid"]; + const blockUid = typeof matchedUid === "string" ? matchedUid : ""; if (!blockUid) { internalError({