Skip to content

Commit d803704

Browse files
authored
ENG-1000 Sync nodes causing jank (#515)
* move from async to backend for queries * merge conflict fix
1 parent 104a862 commit d803704

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

apps/roam/src/components/DiscourseContextOverlay.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const getOverlayInfo = async (tag: string): Promise<DiscourseData> => {
3939
nodes,
4040
relations,
4141
}),
42-
// @ts-ignore - backend to be added to roamjs-components
43-
window.roamAlphaAPI.data.async.q(
42+
window.roamAlphaAPI.data.backend.q(
4443
`[:find ?a :where [?b :node/title "${normalizePageTitle(tag)}"] [?a :block/refs ?b]]`,
4544
),
4645
]);

apps/roam/src/utils/getAllDiscourseNodesSince.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ export const getAllDiscourseNodesSince = async (
9090
[(> ?nodeEditTime ?since)]
9191
]`;
9292

93-
//@ts-ignore - backend to be added to roamjs-components
94-
const allNodes = (await window.roamAlphaAPI.data.async.q(
95-
query,
96-
sinceMs,
93+
const allNodes = (await Promise.resolve(
94+
window.roamAlphaAPI.data.backend.q(query, sinceMs),
9795
)) as unknown as RoamDiscourseNodeData[];
9896

9997
const discourseNodes = getDiscourseNodes();

apps/roam/src/utils/hyde.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,57 +348,61 @@ export const findSimilarNodesUsingHyde = async ({
348348
};
349349

350350
export const getAllPageByUidAsync = async (): Promise<[string, string][]> => {
351-
// @ts-ignore - backend to be added to roamjs-components
352-
const pages = (await window.roamAlphaAPI.data.async.q(
353-
"[:find ?pageName ?pageUid :where [?e :node/title ?pageName] [?e :block/uid ?pageUid]]",
351+
const pages = (await Promise.resolve(
352+
window.roamAlphaAPI.data.backend.q(
353+
"[:find ?pageName ?pageUid :where [?e :node/title ?pageName] [?e :block/uid ?pageUid]]",
354+
),
354355
)) as [string, string][];
355356
return pages;
356357
};
357358

358-
const extractPagesFromChildBlock = async (
359+
export const extractPagesFromChildBlock = async (
359360
tag: string,
360361
): Promise<{ uid: string; text: string }[]> => {
361-
// @ts-ignore - backend to be added to roamjs-components
362-
const results = (await window.roamAlphaAPI.data.async.q(
363-
`[:find ?uid ?title
362+
const results = (await Promise.resolve(
363+
window.roamAlphaAPI.data.backend.q(
364+
`[:find ?uid ?title
364365
:where [?b :node/title "${normalizePageTitle(tag)}"]
365366
[?a :block/refs ?b]
366367
[?p :block/children ?a]
367368
[?p :block/refs ?rf]
368369
[?rf :block/uid ?uid]
369370
[?rf :node/title ?title]]]`,
371+
),
370372
)) as Array<[string, string]>;
371373
return results.map(([uid, title]) => ({ uid, text: title }));
372374
};
373375

374-
const extractPagesFromParentBlock = async (
376+
export const extractPagesFromParentBlock = async (
375377
tag: string,
376378
): Promise<{ uid: string; text: string }[]> => {
377-
// @ts-ignore - backend to be added to roamjs-components
378-
const results = (await window.roamAlphaAPI.data.async.q(
379-
`[:find ?uid ?title
379+
const results = (await Promise.resolve(
380+
window.roamAlphaAPI.data.backend.q(
381+
`[:find ?uid ?title
380382
:where [?b :node/title "${normalizePageTitle(tag)}"]
381383
[?a :block/refs ?b]
382384
[?p :block/parents ?a]
383385
[?p :block/refs ?rf]
384386
[?rf :block/uid ?uid]
385387
[?rf :node/title ?title]]]`,
388+
),
386389
)) as Array<[string, string]>;
387390
return results.map(([uid, title]) => ({ uid, text: title }));
388391
};
389392

390-
const getAllReferencesOnPage = async (
393+
export const getAllReferencesOnPage = async (
391394
pageTitle: string,
392395
): Promise<{ uid: string; text: string }[]> => {
393-
// @ts-ignore - backend to be added to roamjs-components
394-
const referencedPages = (await window.roamAlphaAPI.data.async.q(
395-
`[:find ?uid ?text
396+
const referencedPages = (await Promise.resolve(
397+
window.roamAlphaAPI.data.backend.q(
398+
`[:find ?uid ?text
396399
:where
397400
[?page :node/title "${normalizePageTitle(pageTitle)}"]
398401
[?b :block/page ?page]
399402
[?b :block/refs ?refPage]
400403
[?refPage :block/uid ?uid]
401404
[?refPage :node/title ?text]]`,
405+
),
402406
)) as Array<[string, string]>;
403407
return referencedPages.map(([uid, text]) => ({ uid, text }));
404408
};

apps/roam/src/utils/syncDgNodesToSupabase.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from "./conceptConversion";
1919
import { fetchEmbeddingsForNodes } from "./upsertNodesAsContentWithEmbeddings";
2020
import { convertRoamNodeToLocalContent } from "./upsertNodesAsContentWithEmbeddings";
21-
import { getRoamUrl } from "roamjs-components/dom";
2221
import { render as renderToast } from "roamjs-components/components/Toast";
2322
import { createClient, type DGSupabaseClient } from "@repo/database/lib/client";
2423
import type { Json, CompositeTypes, Enums } from "@repo/database/dbTypes";
@@ -178,9 +177,9 @@ const upsertNodeSchemaToContent = async ({
178177
179178
]
180179
`;
181-
const result = (await window.roamAlphaAPI.data.async.q(
182-
query,
183-
nodeTypesUids,
180+
181+
const result = (await Promise.resolve(
182+
window.roamAlphaAPI.data.backend.q(query, nodeTypesUids),
184183
)) as unknown as RoamDiscourseNodeData[];
185184

186185
const contentData: LocalContentDataInput[] = convertRoamNodeToLocalContent({
@@ -329,8 +328,9 @@ const getAllUsers = async (): Promise<AccountLocalInput[]> => {
329328
[?user-eid :user/uid ?author_local_id]
330329
[(get-else $ ?user-eid :user/display-name "") ?author_name]
331330
]`;
332-
//@ts-ignore - backend to be added to roamjs-components
333-
const result = (await window.roamAlphaAPI.data.async.q(query)) as unknown as {
331+
const result = (await Promise.resolve(
332+
window.roamAlphaAPI.data.backend.q(query),
333+
)) as unknown as {
334334
author_local_id: string;
335335
name: string;
336336
}[];

0 commit comments

Comments
 (0)