Skip to content

Commit cac2598

Browse files
authored
eng-1208 add local flag to fireQuery
1 parent d6d2171 commit cac2598

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

apps/roam/src/utils/fireQuery.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type RelationInQuery = {
3030
export type FireQueryArgs = QueryArgs & {
3131
isCustomEnabled?: boolean;
3232
customNode?: string;
33+
local?: boolean;
3334
context?: {
3435
relationsInQuery?: RelationInQuery[];
3536
customNodes?: DiscourseNode[];
@@ -315,7 +316,7 @@ export const fireQuerySync = (args: FireQueryArgs): QueryResult[] => {
315316
};
316317

317318
const fireQuery: FireQuery = async (_args) => {
318-
const { isCustomEnabled, customNode, ...args } = _args;
319+
const { isCustomEnabled, customNode, local, ...args } = _args;
319320

320321
const { query, formatResult, inputs } = isCustomEnabled
321322
? {
@@ -347,10 +348,15 @@ const fireQuery: FireQuery = async (_args) => {
347348
console.groupEnd();
348349
}
349350

350-
const queryResults = await window.roamAlphaAPI.data.backend.q(
351-
query,
352-
...inputs,
353-
);
351+
let queryResults: unknown[][] = [];
352+
if (local) {
353+
queryResults = await window.roamAlphaAPI.data.async.fast.q(
354+
query,
355+
...inputs,
356+
);
357+
} else {
358+
queryResults = await window.roamAlphaAPI.data.backend.q(query, ...inputs);
359+
}
354360

355361
if (nodeEnv === "development") {
356362
console.timeEnd(`Query - ${queryId}`);

apps/roam/src/utils/getExportTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ const getExportTypes = ({
375375
);
376376
};
377377
const getRelationData = () =>
378-
getRelationDataUtil(allRelations, nodeLabelByType);
378+
getRelationDataUtil({ allRelations, nodeLabelByType, local: true });
379379

380380
const getJsonData = async () => {
381381
const grammar = allRelations.map(({ label, destination, source }) => ({

apps/roam/src/utils/getRelationData.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import internalError from "./internalError";
66

77
// lifted from getExportTypes
88

9-
export const getRelationDataUtil = async (
10-
allRelations: DiscourseRelation[],
11-
nodeLabelByType: Record<string, string>,
12-
) =>
9+
export const getRelationDataUtil = async ({
10+
allRelations,
11+
nodeLabelByType,
12+
local,
13+
}: {
14+
allRelations: DiscourseRelation[];
15+
nodeLabelByType: Record<string, string>;
16+
local?: boolean;
17+
}) =>
1318
Promise.all(
1419
allRelations
1520
.filter(
@@ -24,6 +29,7 @@ export const getRelationDataUtil = async (
2429
? []
2530
: fireQuery({
2631
returnNode: sourceLabel,
32+
local,
2733
conditions: [
2834
{
2935
relation: s.label,
@@ -60,13 +66,13 @@ export const getRelationDataUtil = async (
6066
}),
6167
).then((r) => r.flat());
6268

63-
const getRelationData = async () => {
69+
const getRelationData = async (local?: boolean) => {
6470
const allRelations = getDiscourseRelations();
6571
const allNodes = getDiscourseNodes(allRelations);
6672
const nodeLabelByType = Object.fromEntries(
6773
allNodes.map((a) => [a.type, a.text]),
6874
);
69-
return await getRelationDataUtil(allRelations, nodeLabelByType);
75+
return await getRelationDataUtil({ allRelations, nodeLabelByType, local });
7076
};
7177

7278
export default getRelationData;

apps/roam/src/utils/migrateRelations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const migrateRelations = async (dryRun = false): Promise<number> => {
2020
await new Promise((resolve) => setTimeout(resolve, 150));
2121
try {
2222
const processed = new Set<string>();
23-
const relationData = await getRelationData();
23+
const relationData = await getRelationData(true);
2424
for (const rel of relationData) {
2525
const key = `${rel.source}:${rel.relUid}:${rel.target}`;
2626
if (processed.has(key)) continue;

0 commit comments

Comments
 (0)