Skip to content

Commit c2b1dd9

Browse files
committed
move migrateImportedFromFrontMatter to sync
1 parent 318abfa commit c2b1dd9

2 files changed

Lines changed: 34 additions & 35 deletions

File tree

apps/obsidian/src/index.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import { initializeSupabaseSync } from "~/utils/syncDgNodesToSupabase";
2727
import { FileChangeListener } from "~/utils/fileChangeListener";
2828
import generateUid from "~/utils/generateUid";
2929
import { migrateFrontmatterRelationsToRelationsJson } from "~/utils/relationsStore";
30-
import { collectDiscourseNodesFromVault } from "~/utils/getDiscourseNodes";
31-
import { spaceUriAndLocalIdToRid } from "~/utils/rid";
3230

3331
export default class DiscourseGraphPlugin extends Plugin {
3432
settings: Settings = { ...DEFAULT_SETTINGS };
@@ -45,10 +43,6 @@ export default class DiscourseGraphPlugin extends Plugin {
4543
console.error("Failed to migrate frontmatter relations:", error);
4644
});
4745

48-
await this.migrateImportedFromFrontMatter().catch((error) => {
49-
console.error("Failed to migrate frontmatter:", error);
50-
});
51-
5246
if (this.settings.syncModeEnabled === true) {
5347
void initializeSupabaseSync(this).catch((error) => {
5448
console.error("Failed to initialize Supabase sync:", error);
@@ -401,35 +395,6 @@ export default class DiscourseGraphPlugin extends Plugin {
401395
this.currentViewActions = [];
402396
}
403397

404-
async migrateImportedFromFrontMatter() {
405-
const nodes = await collectDiscourseNodesFromVault(this, true);
406-
for (const node of nodes) {
407-
if (typeof node.frontmatter.importedFromSpaceUri === "string") {
408-
await this.app.fileManager.processFrontMatter(
409-
node.file,
410-
(frontmatter: Record<string, unknown>) => {
411-
const spaceUri = frontmatter.importedFromSpaceUri as string;
412-
// note: we fortunately reused the original Id here.
413-
const nodeId = frontmatter.nodeInstanceId;
414-
if (typeof nodeId !== "string") {
415-
console.error(
416-
`error: missing nodeInstanceId on node ${node.file.path}`,
417-
);
418-
return;
419-
}
420-
try {
421-
const rid = spaceUriAndLocalIdToRid(spaceUri, nodeId, "note");
422-
frontmatter.importedFromRid = rid;
423-
delete frontmatter.importedFromSpaceUri;
424-
} catch (error) {
425-
console.error(error);
426-
}
427-
},
428-
);
429-
}
430-
}
431-
}
432-
433398
async onunload() {
434399
this.cleanupViewActions();
435400
if (this.styleElement) {

apps/obsidian/src/utils/syncDgNodesToSupabase.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
type DiscourseNodeInVault,
2222
collectDiscourseNodesFromVault,
2323
} from "./getDiscourseNodes";
24+
import { spaceUriAndLocalIdToRid } from "./rid";
2425

2526
const DEFAULT_TIME = "1970-01-01";
2627
export type ChangeType = "title" | "content";
@@ -780,6 +781,35 @@ export const cleanupOrphanedNodes = async (
780781
}
781782
};
782783

784+
const migrateImportedFromFrontMatter = async (plugin: DiscourseGraphPlugin) => {
785+
const nodes = await collectDiscourseNodesFromVault(plugin, true);
786+
for (const node of nodes) {
787+
if (typeof node.frontmatter.importedFromSpaceUri === "string") {
788+
await plugin.app.fileManager.processFrontMatter(
789+
node.file,
790+
(frontmatter: Record<string, unknown>) => {
791+
const spaceUri = frontmatter.importedFromSpaceUri as string;
792+
// note: we fortunately reused the original Id here.
793+
const nodeId = frontmatter.nodeInstanceId;
794+
if (typeof nodeId !== "string") {
795+
console.error(
796+
`error: missing nodeInstanceId on node ${node.file.path}`,
797+
);
798+
return;
799+
}
800+
try {
801+
const rid = spaceUriAndLocalIdToRid(spaceUri, nodeId, "note");
802+
frontmatter.importedFromRid = rid;
803+
delete frontmatter.importedFromSpaceUri;
804+
} catch (error) {
805+
console.error(error);
806+
}
807+
},
808+
);
809+
}
810+
}
811+
};
812+
783813
export const initializeSupabaseSync = async (
784814
plugin: DiscourseGraphPlugin,
785815
): Promise<void> => {
@@ -790,6 +820,10 @@ export const initializeSupabaseSync = async (
790820
);
791821
}
792822

823+
await migrateImportedFromFrontMatter(plugin).catch((error) => {
824+
console.error("Failed to migrate frontmatter:", error);
825+
});
826+
793827
await createOrUpdateDiscourseEmbedding(plugin, context).catch((error) => {
794828
new Notice(`Initial sync failed: ${error}`);
795829
console.error("Initial sync failed:", error);

0 commit comments

Comments
 (0)