-
Notifications
You must be signed in to change notification settings - Fork 648
Load session metadata before note content #5789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ComputelessComputer
merged 1 commit into
main
from
fix/session-sidebar-startup-hydration
Jun 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
apps/desktop/src/store/tinybase/persister/session/hydrate.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { beforeEach, describe, expect, test, vi } from "vitest"; | ||
|
|
||
| import { hydrateSessionContent } from "./hydrate"; | ||
| import { loadSingleSession } from "./load"; | ||
|
|
||
| import { ok } from "~/store/tinybase/persister/shared"; | ||
| import { createTestMainStore } from "~/store/tinybase/persister/testing/mocks"; | ||
|
|
||
| vi.mock("./load", () => ({ | ||
| loadSingleSession: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("~/store/tinybase/persister/shared/paths", () => ({ | ||
| getDataDir: vi.fn().mockResolvedValue("/data"), | ||
| })); | ||
|
|
||
| const loadSingleSessionMock = vi.mocked(loadSingleSession); | ||
|
|
||
| describe("hydrateSessionContent", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| test("merges loaded session content without removing other sessions", async () => { | ||
| const store = createTestMainStore(); | ||
| store.setRow("sessions", "session-1", { | ||
| user_id: "user-1", | ||
| created_at: "2024-01-01T00:00:00Z", | ||
| title: "First", | ||
| raw_md: "", | ||
| }); | ||
| store.setRow("sessions", "session-2", { | ||
| user_id: "user-1", | ||
| created_at: "2024-01-02T00:00:00Z", | ||
| title: "Second", | ||
| raw_md: "", | ||
| }); | ||
|
|
||
| loadSingleSessionMock.mockResolvedValue( | ||
| ok({ | ||
| sessions: { | ||
| "session-1": { | ||
| user_id: "user-1", | ||
| created_at: "2024-01-01T00:00:00Z", | ||
| title: "First", | ||
| raw_md: '{"type":"doc"}', | ||
| }, | ||
| }, | ||
| mapping_session_participant: {}, | ||
| tags: {}, | ||
| mapping_tag_session: {}, | ||
| transcripts: {}, | ||
| enhanced_notes: {}, | ||
| session_key_facts: {}, | ||
| }), | ||
| ); | ||
|
|
||
| await hydrateSessionContent(store, "session-1"); | ||
|
|
||
| expect(store.getRowIds("sessions")).toEqual(["session-1", "session-2"]); | ||
| expect(store.getCell("sessions", "session-1", "raw_md")).toBe( | ||
| '{"type":"doc"}', | ||
| ); | ||
| expect(store.getCell("sessions", "session-2", "title")).toBe("Second"); | ||
| }); | ||
| }); |
36 changes: 36 additions & 0 deletions
36
apps/desktop/src/store/tinybase/persister/session/hydrate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { Store } from "tinybase/with-schemas"; | ||
|
|
||
| import type { Schemas } from "@hypr/store"; | ||
| import { asTablesChanges } from "@hypr/tinybase-utils"; | ||
|
|
||
| import { loadSingleSession } from "./load"; | ||
| import type { LoadedSessionData } from "./load"; | ||
|
|
||
| import { getDataDir } from "~/store/tinybase/persister/shared/paths"; | ||
|
|
||
| function hasLoadedRows(data: LoadedSessionData): boolean { | ||
| return Object.values(data).some((table) => Object.keys(table).length > 0); | ||
| } | ||
|
|
||
| export async function hydrateSessionContent( | ||
| store: Store<Schemas>, | ||
| sessionId: string, | ||
| ): Promise<boolean> { | ||
| const dataDir = await getDataDir(); | ||
| const loadResult = await loadSingleSession(dataDir, sessionId); | ||
|
|
||
| if (loadResult.status === "error") { | ||
| console.error( | ||
| `[SessionPersister] hydrate error for ${sessionId}:`, | ||
| loadResult.error, | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| if (!hasLoadedRows(loadResult.data)) { | ||
| return true; | ||
| } | ||
|
|
||
| store.applyChanges(asTablesChanges(loadResult.data)); | ||
| return true; | ||
| } |
44 changes: 44 additions & 0 deletions
44
apps/desktop/src/store/tinybase/persister/session/load/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { beforeEach, describe, expect, test, vi } from "vitest"; | ||
|
|
||
| import { loadAllSessionData } from "./index"; | ||
|
|
||
| const fsSyncMocks = vi.hoisted(() => ({ | ||
| scanAndRead: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@tauri-apps/api/path", () => ({ | ||
| sep: () => "/", | ||
| })); | ||
| vi.mock("@hypr/plugin-fs-sync", () => ({ commands: fsSyncMocks })); | ||
|
|
||
| describe("loadAllSessionData", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| fsSyncMocks.scanAndRead.mockResolvedValue({ | ||
| status: "ok", | ||
| data: { files: {}, dirs: [] }, | ||
| }); | ||
| }); | ||
|
|
||
| test("scans only metadata when content is excluded", async () => { | ||
| await loadAllSessionData("/data", { includeContent: false }); | ||
|
|
||
| expect(fsSyncMocks.scanAndRead).toHaveBeenCalledWith( | ||
| "/data/sessions", | ||
| ["_meta.json"], | ||
| true, | ||
| null, | ||
| ); | ||
| }); | ||
|
|
||
| test("scans metadata and content by default", async () => { | ||
| await loadAllSessionData("/data"); | ||
|
|
||
| expect(fsSyncMocks.scanAndRead).toHaveBeenCalledWith( | ||
| "/data/sessions", | ||
| ["_meta.json", "transcript.json", "*.md"], | ||
| true, | ||
| null, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.