Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): cache long-thread SQLite reads #22356

Closedsisodias(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/22356/headopened View on GitHub

Showing 3 changed files with 78 additions and 3 deletions.

x
0 of 3 viewed, 3 left
52 additions and 0 deletionsapps/server/src/persistence/Sqlite.test.tsModified
View file
@@ -11,6 +11,9 @@
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as SqlClient from "effect/sql/SqlClient";
+import * as Statement from "effect/sql/Statement";
+import type * as Tracer from "effect/Tracer";
+import { readOnly } from "@t3tools/shared/nodeSqliteClient";
import { vi } from "vite-plus/test";
​
import * as SqlitePersistence from "./Sqlite.ts";
@@ -183,3 +186,52 @@
Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
});
+​
+it.effect("configures the page cache and mapped reads on both file connections", () => {
+ const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-sqlite-cache-"));
+ const dbPath = NodePath.join(tempDir, "state.sqlite");
+ return Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+ yield* sql`CREATE TABLE cache_probe(id INTEGER PRIMARY KEY)`;
+ yield* sql`INSERT INTO cache_probe VALUES (1)`;
+ const reference = new NodeSqlite.DatabaseSync(dbPath, { readOnly: true });
+ let expectedMmap;
+ try {
+ expectedMmap = reference.prepare("PRAGMA mmap_size = 2147483648").get()?.mmap_size;
+ } finally {
+ reference.close();
+ }