feat: Settings reclaims freed database space in one click #32941
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/32941/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/mobile/src/features/settings/components/DatabaseStorageNotice.tsx line 45OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -31,4 +41,5 @@3141 return (3242 <SettingsSection3343 title="Reclaim database space"34- footer="These databases still hold space freed by history cleanup. Run the command on each machine to reclaim it. It restarts the background service. Quit the desktop app first if it hosts the environment."44+ footer={`These databases still hold space freed by history cleanup.${45+ visible.every((recommendation) => recommendation.status.canReclaim === true)apps/server/src/persistence/DatabaseMaintenance.ts line 301OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -232,0 +281,21 @@281+ ? "Another program kept the database open. Close other T3 Code apps and t3 commands on this machine, then try again."282+ : error.message,283+ )284+ .pipe(285+ Effect.andThen(Effect.logWarning("Database space reclamation failed", { error })),286+ ),287+ }),288+ );289+ },290+ Effect.catchCause((cause) => Effect.logWarning("Database space reclamation failed", { cause })),291+);292+293+// SQLite's search order for its temporary files (unixTempFileDir in os_unix.c).294+const sqliteTempDirectory = Effect.gen(function* () {295+ if ((yield* HostProcess.Platform) === "win32") return NodeOS.tmpdir();296+ const fs = yield* FileSystem.FileSystem;297+ const env = yield* HostProcess.Environment;298+ for (const directory of [env.SQLITE_TMPDIR, env.TMPDIR, "/var/tmp", "/usr/tmp", "/tmp"]) {299+ if (directory === undefined || directory === "") continue;300+ const info = yield* fs.stat(directory).pipe(Effect.option);301+ if (Option.isSome(info) && info.value.type === "Directory") return directory;
- apps/mobile/src/features/settings/components/DatabaseStorageNotice.tsx lines 44 to 48OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -31,4 +41,8 @@3141 return (3242 <SettingsSection3343 title="Reclaim database space"34- footer="These databases still hold space freed by history cleanup. Run the command on each machine to reclaim it. It restarts the background service. Quit the desktop app first if it hosts the environment."44+ footer={`These databases still hold space freed by history cleanup.${45+ visible.every((recommendation) => recommendation.status.canReclaim === true)46+ ? ""47+ : " Run the command on each machine to reclaim it. It restarts the background service. Quit the desktop app first if it hosts the environment."48+ }`}apps/server/src/persistence/DatabaseStorage.ts lines 212 to 213Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -152,0 +193,21 @@193+ // Only databases without automatic shrinking need it; a stale dialog can ask after another client's repair.194+ if ((yield* readLayout).autoVacuum !== 0) {195+ return yield* new DatabaseReclaimError({196+ reason: "This database already shrinks on its own. Nothing to reclaim.",197+ });198+ }199+ const { databaseBytes, reclaimableBytes } = yield* readPages;200+ const shortfall = yield* DatabaseMaintenance.reclaimSpaceShortfall(201+ config.dbPath,202+ databaseBytes - reclaimableBytes,203+ ).pipe(204+ Effect.provideService(FileSystem.FileSystem, fs),205+ Effect.provideService(Path.Path, path),206+ );207+ if (shortfall !== null) {208+ return yield* new DatabaseReclaimError({209+ reason: `Reclaiming needs ${formatGiB(shortfall.neededBytes)} of free disk space on this machine. ${formatGiB(shortfall.freeBytes)} is free.`,210+ });211+ }212+ yield* fs.remove(reclaimFiles.failure, { force: true });213+ reclaimFailure = undefined;
- apps/mobile/src/features/settings/components/DatabaseStorageNotice.tsx line 124OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -64,0 +104,21 @@104+ readonly target: SettingsTarget;105+ readonly status: DatabaseStorageStatus;106+ readonly reclaimable: boolean;107+}) {108+ const { environmentId, label } = target;109+ const reclaim = useAtomCommand(serverEnvironment.reclaimDatabaseSpace, { reportFailure: false });110+ const [requested, setRequested] = useState(false);111+ const amount = formatGiB(status.reclaimableBytes);112+ if (!reclaimable) {113+ return (114+ <SettingsActionRow115+ icon="doc.on.doc"116+ label={label}117+ description={status.compactCommand}118+ detail={amount}119+ onPress={() => copyTextWithHaptic(status.compactCommand, { target: "command" })}120+ />121+ );122+ }123+ // A failed repair reports back after the restart, which ends the wait.124+ const restarting = requested && status.reclaimFailure === undefined;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- docs/user/background-service.md lines 171 to 172Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -168,5 +168,5 @@168168 Settings > Maintenance (mobile) suggests the repair when at least 1 GiB can be169169 reclaimed.170170171-Run `t3 doctor` on the machine that hosts the environment. It reports the172-database size and the space it can reclaim, then asks which repairs to run;171+When the desktop app or the background service runs T3 Code on that machine,172+select **Reclaim** in Settings on web or desktop. T3 Code checks for free disk
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.





macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed