Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop fsyncing SQLite on every commit so slow disks no longer drop clients #19205

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19205/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 2 changed files with 21 additions and 0 deletions.

x
0 of 2 viewed, 2 left
15 additions and 0 deletionsapps/server/src/persistence/Sqlite.test.tsModified
View file
@@ -114,6 +114,21 @@
});
​
+it.effect("only fsyncs the database file at WAL checkpoints", () => {
+ const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-sqlite-sync-"));
+ const dbPath = NodePath.join(tempDir, "state.sqlite");
+​
+ return Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+ const rows = yield* sql<{ readonly synchronous: number }>`PRAGMA synchronous`;
+ // 1 is NORMAL.
+ assert.equal(rows[0]?.synchronous, 1);
+ }).pipe(
+ Effect.provide(SqlitePersistence.layerFromPath(dbPath).pipe(Layer.provide(NodeServices.layer))),
+ Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
+ );
+});
+​
it.effect("applies busy_timeout in the shared persistence setup", () =>
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
6 additions and 0 deletionsapps/server/src/persistence/Sqlite.tsModified
View file
@@ -19,6 +19,12 @@
yield* sql`PRAGMA busy_timeout = 5000;`;
yield* sql`PRAGMA foreign_keys = ON;`;
yield* sql`PRAGMA journal_mode = WAL;`;