Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): connects no longer wait on editor and SSH target discovery #14519

Mergedsaphid(GitHub profile, opens in a new tab)merged 12 commits intomain fromrefs/pull/14519/headmerged by maria-rcks View on GitHub

Showing 7 changed files with 185 additions and 1 deletion (loading 5).

x
0 of 7 viewed, 7 left
8 additions and 1 deletionapps/server/src/environment/RemoteOpenTargets.tsModified
View file
@@ -7,7 +7,10 @@
import * as Layer from "effect/Layer";
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
​
+import { makeStaleWhileRevalidate } from "./staleWhileRevalidate.ts";
+​
const SSH_PORT = 22;
+const TARGETS_CACHE_TTL = "60 seconds";
​
export class RemoteOpenTargets extends Context.Service<
RemoteOpenTargets,
@@ -21,7 +24,7 @@
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const net = yield* NetService.NetService;
​
- const resolveTargets = Effect.gen(function* () {
+ const discoverTargets = Effect.gen(function* () {
// Check both loopback families: sshd can be bound IPv6-only.
const sshdListening = yield* Effect.zipWith(
net.hasListenerOnHost(SSH_PORT, "127.0.0.1"),
@@ -78,6 +81,10 @@
return targets;
});
​
+ // Advertised on every client connect; probing sshd and tailscaled is slow
+ // on a loaded host, so serve the last result while it refreshes.
+ const resolveTargets = yield* makeStaleWhileRevalidate(discoverTargets, TARGETS_CACHE_TTL);
+​