Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/roam/src/components/canvas/Tldraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
? { x: lastTime.x + w * 0.025, y: lastTime.y + h * 0.05 }
: { x: x - DEFAULT_WIDTH / 2, y: y - DEFAULT_HEIGHT / 2 };
const nodeType = findDiscourseNode({
uid: e.detail.uid,
uid: e.detail.uid || "",
nodes: allNodes,
});
if (nodeType) {
Expand Down
5 changes: 2 additions & 3 deletions apps/roam/src/utils/findDiscourseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ const findDiscourseNode = ({
title,
nodes = getDiscourseNodes(),
}: {
uid?: string;
uid: string;
title?: string;
nodes?: DiscourseNode[];
}): DiscourseNode | false => {
if (uid === undefined) return false;
if (typeof discourseNodeTypeCache[uid] !== "undefined") {
return discourseNodeTypeCache[uid];
}

const matchingNode =
nodes.find((node) =>
title === undefined
? matchDiscourseNode({ ...node, uid: uid })
? matchDiscourseNode({ ...node, uid })
: matchDiscourseNode({ ...node, title }),
) || false;
discourseNodeTypeCache[uid] = matchingNode;
Expand Down
2 changes: 1 addition & 1 deletion apps/roam/src/utils/formatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const getReferencedNodeInFormat = ({
}) => {
let format = providedFormat;
if (!format) {
const discourseNode = findDiscourseNode({ uid });
const discourseNode = findDiscourseNode({ uid: uid || "" });
if (discourseNode) format = discourseNode.format;
}
if (!format) return null;
Expand Down
5 changes: 2 additions & 3 deletions apps/roam/src/utils/initializeObserversAndListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ export const initObservers = async ({
text: "(BETA) Suggestive Mode Enabled",
}).value;

const nodes = getDiscourseNodes();
const node = findDiscourseNode({ title, nodes });
const uid = getPageUidByPageTitle(title);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing UID lets us use the findDiscourseNode cache, at the tradeoff of running a pull on every page. Queries on every page are not ideal, but this pull is pretty insignificant.

const node = findDiscourseNode({ uid, title });
const isDiscourseNode = node && node.backedBy !== "default";
if (isDiscourseNode) {
const uid = getPageUidByPageTitle(title);
if (isSuggestiveModeEnabled) {
renderPossibleDuplicates(h1, title, node);
}
Expand Down