Skip to content

Commit 5b1ca3e

Browse files
committed
Defer Obsidian reader filters
1 parent 53609fd commit 5b1ca3e

2 files changed

Lines changed: 7 additions & 58 deletions

File tree

apps/obsidian/src/utils/importNodes.ts

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@ type PublishedNode = {
3131
authorId: number | undefined;
3232
};
3333

34-
type ObsidianNativeVariant = "direct" | "full";
35-
36-
const PLAIN_TEXT_CONTENT_TYPE = "text/plain";
37-
const OBSIDIAN_MARKDOWN_CONTENT_TYPE = "text/obsidian+markdown";
38-
39-
const getObsidianNativeContentType = (
40-
variant: ObsidianNativeVariant,
41-
): string =>
42-
variant === "direct"
43-
? PLAIN_TEXT_CONTENT_TYPE
44-
: OBSIDIAN_MARKDOWN_CONTENT_TYPE;
45-
46-
const isObsidianNativeContentRow = ({
47-
variant,
48-
content_type,
49-
}: {
50-
variant: string | null;
51-
content_type: string | null;
52-
}): boolean =>
53-
(variant === "direct" && content_type === PLAIN_TEXT_CONTENT_TYPE) ||
54-
(variant === "full" && content_type === OBSIDIAN_MARKDOWN_CONTENT_TYPE);
55-
5634
export const getPublishedNodesForGroups = async ({
5735
client,
5836
groupIds,
@@ -71,14 +49,9 @@ export const getPublishedNodesForGroups = async ({
7149
const { data, error } = await client
7250
.from("my_contents")
7351
.select(
74-
"source_local_id, space_id, text, created, last_modified, variant, content_type, metadata, author_id",
52+
"source_local_id, space_id, text, created, last_modified, variant, metadata, author_id",
7553
)
76-
.neq("space_id", currentSpaceId)
77-
.in("variant", ["direct", "full"])
78-
.in("content_type", [
79-
PLAIN_TEXT_CONTENT_TYPE,
80-
OBSIDIAN_MARKDOWN_CONTENT_TYPE,
81-
]);
54+
.neq("space_id", currentSpaceId);
8255

8356
if (error) {
8457
console.error("Error fetching published nodes:", error);
@@ -96,15 +69,13 @@ export const getPublishedNodesForGroups = async ({
9669
created: string | null;
9770
last_modified: string | null;
9871
variant: string | null;
99-
content_type: string | null;
10072
author_id: number | null;
10173
metadata: Json;
10274
};
10375

10476
const key = (r: Row) => `${r.space_id ?? ""}\t${r.source_local_id ?? ""}`;
10577
const groups = new Map<string, Row[]>();
10678
for (const row of data as Row[]) {
107-
if (!isObsidianNativeContentRow(row)) continue;
10879
if (row.source_local_id == null || row.space_id == null) continue;
10980
const k = key(row);
11081
if (!groups.has(k)) groups.set(k, []);
@@ -121,10 +92,7 @@ export const getPublishedNodesForGroups = async ({
12192
const latest = withDate.reduce((a, b) =>
12293
(a.last_modified ?? "") >= (b.last_modified ?? "") ? a : b,
12394
);
124-
const direct = rows.find(
125-
(r) =>
126-
r.variant === "direct" && r.content_type === PLAIN_TEXT_CONTENT_TYPE,
127-
);
95+
const direct = rows.find((r) => r.variant === "direct");
12896
const text = direct?.text ?? latest.text ?? "";
12997
const createdAt = latest.created
13098
? new Date(latest.created + "Z").valueOf()
@@ -282,7 +250,6 @@ export const fetchNodeContent = async ({
282250
.eq("source_local_id", nodeInstanceId)
283251
.eq("space_id", spaceId)
284252
.eq("variant", variant)
285-
.eq("content_type", getObsidianNativeContentType(variant))
286253
.maybeSingle();
287254

288255
if (error || !data || data.text == null) {
@@ -317,7 +284,6 @@ export const fetchNodeContentWithMetadata = async ({
317284
.eq("source_local_id", nodeInstanceId)
318285
.eq("space_id", spaceId)
319286
.eq("variant", variant)
320-
.eq("content_type", getObsidianNativeContentType(variant))
321287
.maybeSingle();
322288

323289
if (error || !data || data.text == null) {
@@ -359,16 +325,10 @@ const fetchNodeContentForImport = async ({
359325
} | null> => {
360326
const { data, error } = await client
361327
.from("my_contents")
362-
.select(
363-
"text, created, last_modified, variant, content_type, metadata, author_id",
364-
)
328+
.select("text, created, last_modified, variant, metadata, author_id")
365329
.eq("source_local_id", nodeInstanceId)
366330
.eq("space_id", spaceId)
367-
.in("variant", ["direct", "full"])
368-
.in("content_type", [
369-
PLAIN_TEXT_CONTENT_TYPE,
370-
OBSIDIAN_MARKDOWN_CONTENT_TYPE,
371-
]);
331+
.in("variant", ["direct", "full"]);
372332

373333
if (error) {
374334
console.error("Error fetching node content for import:", error);
@@ -381,16 +341,10 @@ const fetchNodeContentForImport = async ({
381341
last_modified: string | null;
382342
author_id: number | null;
383343
variant: string | null;
384-
content_type: string | null;
385344
metadata: Json;
386345
}>;
387-
const direct = rows.find(
388-
(r) => r.variant === "direct" && r.content_type === PLAIN_TEXT_CONTENT_TYPE,
389-
);
390-
const full = rows.find(
391-
(r) =>
392-
r.variant === "full" && r.content_type === OBSIDIAN_MARKDOWN_CONTENT_TYPE,
393-
);
346+
const direct = rows.find((r) => r.variant === "direct");
347+
const full = rows.find((r) => r.variant === "full");
394348
const authorId = full?.author_id ?? direct?.author_id ?? null;
395349

396350
if (
@@ -441,7 +395,6 @@ export const getSourceContentDates = async ({
441395
.eq("source_local_id", nodeInstanceId)
442396
.eq("space_id", spaceId)
443397
.eq("variant", "direct")
444-
.eq("content_type", PLAIN_TEXT_CONTENT_TYPE)
445398
.maybeSingle();
446399
if (error || !data) return null;
447400
return {
@@ -1572,7 +1525,6 @@ export const refreshImportedFile = async ({
15721525
.eq("space_id", spaceId)
15731526
.eq("source_local_id", frontmatter.nodeInstanceId)
15741527
.eq("variant", "direct")
1575-
.eq("content_type", PLAIN_TEXT_CONTENT_TYPE)
15761528
.maybeSingle();
15771529
const metadata = metadataResp.data?.metadata;
15781530
const filePath: string | undefined =

apps/obsidian/src/utils/publishNode.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import type { DiscourseNodeInVault } from "./getDiscourseNodes";
2323
import type { SupabaseContext } from "./supabaseContext";
2424
import type { TablesInsert } from "@repo/database/dbTypes";
2525

26-
const OBSIDIAN_MARKDOWN_CONTENT_TYPE = "text/obsidian+markdown";
27-
2826
export const getPublishedToGroups = (
2927
frontmatter: FrontMatterCache | Record<string, unknown>,
3028
): string[] => {
@@ -430,7 +428,6 @@ export const publishNodeToGroup = async ({
430428
.eq("source_local_id", nodeId)
431429
.eq("space_id", spaceId)
432430
.eq("variant", "full")
433-
.eq("content_type", OBSIDIAN_MARKDOWN_CONTENT_TYPE)
434431
.maybeSingle();
435432
if (idResponse.error || !idResponse.data) {
436433
throw idResponse.error || new Error("no data while fetching node");

0 commit comments

Comments
 (0)