Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/server/src/orchestration-v2/ShellStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
OrchestrationProjectShell as ProjectShellSchema,
OrchestrationV2ThreadShell as ThreadShellSchema,
} from "@t3tools/contracts";
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
import * as Clock from "effect/Clock";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
Expand Down Expand Up @@ -46,13 +47,16 @@ export const loadShellSnapshotParts = <E1, E2, E3, E4>(input: {
readonly latestSequence: Effect.Effect<number, E4>;
}) =>
Effect.gen(function* () {
const read = yield* input.sql.withTransaction(
Effect.all({
decodeThreads: input.readThreads,
projects: input.listProjects,
snapshotSequence: input.latestSequence,
}),
);
// Read on the reader worker, off the event loop and the writer.
const read = yield* input.sql
.withTransaction(
Effect.all({
decodeThreads: input.readThreads,
projects: input.listProjects,
snapshotSequence: input.latestSequence,
}),
)
.pipe(NodeSqliteClient.readOnly);
return {
projects: read.projects,
threads: yield* read.decodeThreads,
Expand Down
13 changes: 9 additions & 4 deletions apps/server/src/orchestration-v2/ThreadPullRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type ThreadLinkedPullRequest,
} from "@t3tools/contracts";
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as Crypto from "effect/Crypto";
Expand Down Expand Up @@ -127,10 +128,14 @@ export const make = Effect.gen(function* () {
*/
const readThreadSnapshot = ({ threadId, backfill }: RefreshRequest) =>
threadId === null
? orchestrator.getShellSnapshot({
location: "active",
unsettledOnly: !(backfill || pendingBackfill.size > 0),
})
? orchestrator
.getShellSnapshot({
location: "active",
unsettledOnly: !(backfill || pendingBackfill.size > 0),
})
// Reads every active thread once a minute: run it off the event loop. Writes keep
// landing during the read, and the snapshot's sequence guards the sync against them.
.pipe(NodeSqliteClient.readOnly)
: Effect.gen(function* () {
// Read the sequence first. The thread is then at least this new, so a
// sync guarded by the sequence is rejected rather than missing a change.
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/persistence/Sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const layerFromPath = Effect.fn("makeSqlitePersistenceLive")(function* (d
layerSetup,
NodeSqliteClient.layer({
filename: dbPath,
readerWorker: true,
spanAttributes: {
"db.name": path.basename(dbPath),
"service.name": "t3code-server",
Expand Down
Loading
Loading