Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): queued SQLite reads stop waiting on one reader while another is free #27979

MergedPyseph(GitHub profile, opens in a new tab)merged 9 commits intomain fromrefs/pull/27979/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 131 additions and 35 deletions.

x
0 of 2 viewed, 2 left
75 additions and 0 deletionspackages/shared/src/nodeSqliteClient.test.tsModified
View file
@@ -15,6 +15,7 @@
import * as Statement from "effect/sql/Statement";
import { ChildProcess, ChildProcessSpawner } from "effect/process";
import * as Stream from "effect/Stream";
+import * as TestClock from "effect/testing/TestClock";
import type * as Tracer from "effect/Tracer";
import { vi } from "vite-plus/test";
​
@@ -426,6 +427,80 @@
​
+it.effect("gives a queued read the first reader that frees up", () =>
+ withReaderClient((sql) =>
+ Effect.gen(function* () {
+ const holders = yield* Effect.forEach([0, 1, 2, 3], () =>
+ Effect.gen(function* () {
+ const held = yield* Deferred.make<void>();
+ const release = yield* Deferred.make<void>();
+ const fiber = yield* sql
+ .withTransaction(
+ countEntries(sql).pipe(
+ Effect.andThen(Deferred.succeed(held, undefined)),
+ Effect.andThen(Deferred.await(release)),
+ ),
+ )
+ .pipe(SqliteClient.readOnly, Effect.forkChild);
+ yield* Deferred.await(held);
+ return { fiber, release };