Skip to content

Commit 77b4cfd

Browse files
committed
fix a query bug, use supabase t get all nodes
1 parent d803704 commit 77b4cfd

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

apps/roam/src/utils/getAllDiscourseNodesSince.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ export const getAllDiscourseNodesSince = async (
7575
const result: RoamDiscourseNodeData[] = [];
7676

7777
const query = `[
78-
:find ?node-title ?uid ?nodeCreateTime ?nodeEditTime ?author_local_id ?author_name
79-
:keys text source_local_id created last_modified author_local_id author_name
80-
:in $ ?since
81-
:where
82-
[?node :node/title ?node-title]
83-
[?node :block/uid ?uid]
84-
[?node :create/time ?nodeCreateTime]
85-
[?node :edit/time ?nodeEditTime]
86-
[?node :create/user ?user-eid]
87-
[?user-eid :user/uid ?author_local_id]
88-
[?node :edit/user ?eu]
89-
[(get-else $ ?eu :user/display-name "Unknown-person") ?author_name]
90-
[(> ?nodeEditTime ?since)]
91-
]`;
9278
79+
:find ?node-title ?uid ?nodeCreateTime ?nodeEditTime ?author_local_id ?author_name
80+
:keys text source_local_id created last_modified author_local_id author_name
81+
:in $ ?since
82+
:where
83+
[?node :node/title ?node-title]
84+
[?node :block/uid ?uid]
85+
[?node :create/time ?nodeCreateTime]
86+
[?node :create/user ?user-eid]
87+
[?user-eid :user/uid ?author_local_id]
88+
[(get-else $ ?user-eid :user/display-name "Unknown-Creator") ?author_name]
89+
[(get-else $ ?node :edit/time 0) ?nodeEditTime]
90+
[(get-else $ ?node :edit/time ?nodeCreateTime) ?filterTime]
91+
[(> ?filterTime ?since)]
92+
]`;
9393
const allNodes = (await Promise.resolve(
9494
window.roamAlphaAPI.data.backend.q(query, sinceMs),
9595
)) as unknown as RoamDiscourseNodeData[];

apps/roam/src/utils/hyde.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { getLoggedInClient } from "./supabaseContext";
1+
import { getLoggedInClient, getSupabaseContext } from "./supabaseContext";
22
import { Result } from "./types";
33
import normalizePageTitle from "roamjs-components/queries/normalizePageTitle";
44
import findDiscourseNode from "./findDiscourseNode";
55
import { nextApiRoot } from "@repo/utils/execContext";
66
import { DiscourseNode } from "./getDiscourseNodes";
77
import getExtensionAPI from "roamjs-components/util/extensionApiContext";
8+
import { getAllNodes } from "@repo/database/lib/queries";
89

910
type ApiEmbeddingResponse = {
1011
data: Array<{
@@ -455,26 +456,30 @@ export const performHydeSearch = async ({
455456
);
456457

457458
if (useAllPagesForSuggestions) {
458-
// TODO: Use Supabase to get all pages
459-
candidateNodesForHyde = (await getAllPageByUidAsync())
460-
.map(([pageName, pageUid]) => {
461-
if (!pageUid || pageUid === blockUid) return null;
462-
const node = findDiscourseNode(pageUid);
463-
if (
464-
!node ||
465-
node.backedBy === "default" ||
466-
!validTypes.includes(node.type) ||
467-
existingUids.has(pageUid)
468-
) {
469-
return null;
470-
}
459+
const context = await getSupabaseContext();
460+
if (!context) return [];
461+
const supabase = await getLoggedInClient();
462+
const spaceId = context.spaceId;
463+
if (!supabase) return [];
464+
465+
candidateNodesForHyde = (
466+
await getAllNodes({
467+
supabase,
468+
spaceId,
469+
fields: { content: ["source_local_id", "text"] },
470+
ofTypes: validTypes,
471+
pagination: { limit: 10000 },
472+
})
473+
)
474+
.map((c) => {
475+
const node = findDiscourseNode(c.Content?.source_local_id || "");
471476
return {
472-
uid: pageUid,
473-
text: pageName,
474-
type: node.type,
475-
} as SuggestedNode;
477+
uid: c.Content?.source_local_id || "",
478+
text: c.Content?.text || "",
479+
type: node ? node.type : "",
480+
};
476481
})
477-
.filter((n): n is SuggestedNode => n !== null);
482+
.filter((n) => n.uid && n.text && n.type);
478483
} else {
479484
const referenced: { uid: string; text: string }[] = [];
480485
if (shouldGrabFromReferencedPages) {

packages/database/src/lib/queries.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ const composeConceptQuery = ({
325325
q += `, relations:concept_in_relations!inner(${args.join(",\n")})`;
326326
}
327327
let query = supabase.from("my_concepts").select(q);
328-
if (scope.type === 'nodes') {
328+
if (scope.type === "nodes") {
329329
query = query.eq("arity", 0);
330330
} else if (scope.type === 'relations') {
331331
query = query.gt("arity", 0);
@@ -599,19 +599,21 @@ export const getAllNodes = async ({
599599
supabase,
600600
spaceId,
601601
author,
602+
ofTypes,
602603
fields = { concepts: CONCEPT_FIELDS, content: CONTENT_FIELDS },
603604
pagination,
604605
}: {
605606
supabase: DGSupabaseClient;
606607
spaceId?: number;
607608
author?: string;
609+
ofTypes?: string[];
608610
fields?: FieldSelection;
609611
pagination?: PaginationOptions;
610612
}): Promise<PConceptFull[]> => {
611613
return getConcepts({
612614
supabase,
613615
spaceId,
614-
scope: { type: "nodes", author },
616+
scope: { type: "nodes", author, ofTypes },
615617
fields,
616618
pagination,
617619
});

0 commit comments

Comments
 (0)