Skip to content

Commit 57997db

Browse files
t3dotggclaude
andcommitted
chore: Reclaim is web and desktop only for now
Mobile keeps the copy-the-command hint from main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fa66f6a commit 57997db

2 files changed

Lines changed: 24 additions & 122 deletions

File tree

Lines changed: 16 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
11
import { useAtomSet, useAtomValue } from "@effect/atom-react";
2-
import {
3-
isAtomCommandInterrupted,
4-
squashAtomCommandFailure,
5-
} from "@t3tools/client-runtime/state/runtime";
6-
import {
7-
databaseReclaimMinutes,
8-
type DatabaseStorageStatus,
9-
type EnvironmentId,
10-
} from "@t3tools/contracts";
11-
import { Atom, AsyncResult } from "effect/reactivity";
12-
import { useState } from "react";
13-
import { Alert } from "react-native";
2+
import { AsyncResult } from "effect/reactivity";
143

154
import { copyTextWithHaptic } from "../../../lib/copyTextWithHaptic";
165
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../../state/preferences";
176
import { serverEnvironment } from "../../../state/server";
18-
import { useAtomCommand } from "../../../state/use-atom-command";
197
import type { SettingsTarget } from "../settings-environment-filter";
208
import { ListActionRow as SettingsActionRow } from "../../../components/ui/ListActionRow";
219
import { SettingsSection } from "./SettingsSection";
2210

23-
const formatGiB = (bytes: number) => `${(bytes / 1024 ** 3).toFixed(1)} GiB`;
24-
25-
// Keyed by a JSON array of environment ids, like the recommendations it pairs with.
26-
const reclaimPermissionsAtom = Atom.family((environmentIdsKey: string) =>
27-
Atom.make((get) =>
28-
(JSON.parse(environmentIdsKey) as EnvironmentId[]).map((environmentId) =>
29-
get(serverEnvironment.reclaimDatabaseSpace.permissionAtom(environmentId)),
30-
),
31-
),
32-
);
33-
34-
/** Offers to reclaim the space on every machine whose database still holds at least 1 GiB of freed pages. */
11+
/** Suggests `t3 doctor` on every machine whose database still holds at least 1 GiB of freed pages. */
3512
export function DatabaseStorageNotice({
3613
targets,
3714
}: {
3815
readonly targets: readonly SettingsTarget[];
3916
}) {
40-
const environmentIds = targets.map((target) => target.environmentId);
41-
const environmentIdsKey = JSON.stringify(environmentIds);
4217
const recommendations = useAtomValue(
43-
serverEnvironment.databaseCompactionRecommendations(environmentIdsKey),
18+
serverEnvironment.databaseCompactionRecommendations(
19+
JSON.stringify(targets.map((target) => target.environmentId)),
20+
),
4421
);
45-
const permissions = useAtomValue(reclaimPermissionsAtom(environmentIdsKey));
46-
const reclaimable = (environmentId: EnvironmentId, status: DatabaseStorageStatus) =>
47-
status.canReclaim === true && permissions[environmentIds.indexOf(environmentId)] === true;
4822
const preferences = useAtomValue(mobilePreferencesAtom);
4923
const updatePreferences = useAtomSet(updateMobilePreferencesAtom);
5024
const dismissed = AsyncResult.isSuccess(preferences)
@@ -57,25 +31,18 @@ export function DatabaseStorageNotice({
5731
return (
5832
<SettingsSection
5933
title="Reclaim database space"
60-
footer={`These databases still hold space freed by history cleanup.${
61-
visible.every((recommendation) =>
62-
reclaimable(recommendation.environmentId, recommendation.status),
63-
)
64-
? ""
65-
: " Run the command on each machine to reclaim it. It restarts the background service. Quit the desktop app first if it hosts the environment."
66-
}`}
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."
6735
>
68-
{visible.map(({ environmentId, status }) => {
69-
const target = targets.find((candidate) => candidate.environmentId === environmentId);
70-
return target ? (
71-
<DatabaseRow
72-
key={environmentId}
73-
target={target}
74-
status={status}
75-
reclaimable={reclaimable(environmentId, status)}
76-
/>
77-
) : null;
78-
})}
36+
{visible.map(({ environmentId, status }) => (
37+
<SettingsActionRow
38+
key={environmentId}
39+
icon="doc.on.doc"
40+
label={targets.find((target) => target.environmentId === environmentId)?.label ?? ""}
41+
description={status.compactCommand}
42+
detail={`${(status.reclaimableBytes / 1024 ** 3).toFixed(1)} GiB`}
43+
onPress={() => copyTextWithHaptic(status.compactCommand, { target: "command" })}
44+
/>
45+
))}
7946
<SettingsActionRow
8047
icon="xmark"
8148
label="Dismiss"
@@ -95,69 +62,3 @@ export function DatabaseStorageNotice({
9562
</SettingsSection>
9663
);
9764
}
98-
99-
function DatabaseRow({
100-
target,
101-
status,
102-
reclaimable,
103-
}: {
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-
<SettingsActionRow
115-
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;
125-
const minutes = databaseReclaimMinutes(status);
126-
const start = async () => {
127-
setRequested(true);
128-
const result = await reclaim({ environmentId, input: {} });
129-
if (result._tag === "Success") return;
130-
setRequested(false);
131-
if (isAtomCommandInterrupted(result)) return;
132-
const error = squashAtomCommandFailure(result);
133-
Alert.alert(
134-
`Could not reclaim space on ${label}`,
135-
error instanceof Error ? error.message : "An error occurred.",
136-
);
137-
};
138-
return (
139-
<SettingsActionRow
140-
icon="arrow.clockwise"
141-
label={label}
142-
description={
143-
restarting
144-
? `Restarting. Back in about ${minutes} min.`
145-
: status.reclaimFailure === undefined
146-
? `Restarts T3 Code there. It is offline for about ${minutes} min.`
147-
: `The last attempt failed: ${status.reclaimFailure}`
148-
}
149-
detail={amount}
150-
loading={restarting}
151-
onPress={() =>
152-
Alert.alert(
153-
`Reclaim ${amount} on ${label}?`,
154-
`T3 Code on ${label} stops, rebuilds its database, and starts again. It is offline for about ${minutes} min. Running agents stop when it restarts.`,
155-
[
156-
{ text: "Cancel", style: "cancel" },
157-
{ text: "Restart and reclaim", onPress: () => void start() },
158-
],
159-
)
160-
}
161-
/>
162-
);
163-
}

‎docs/user/background-service.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ Settings > Maintenance (mobile) suggests the repair when at least 1 GiB can be
169169
reclaimed.
170170

171171
When the desktop app or the background service runs T3 Code on that machine,
172-
select **Reclaim** there. T3 Code checks for free disk space, then stops,
173-
repairs the database, and starts again. It is offline while the repair runs, and
174-
running agents stop. If the repair fails, Settings shows why.
175-
176-
For a server you started by hand, run `t3 doctor` on the machine that hosts the
177-
environment. It reports the
178-
database size and the space it can reclaim, then asks which repairs to run;
172+
select **Reclaim** in Settings on web or desktop. T3 Code checks for free disk
173+
space, then stops, repairs the database, and starts again. It is offline while
174+
the repair runs, and running agents stop. If the repair fails, Settings shows
175+
why.
176+
177+
In other cases, such as a server you started by hand, run `t3 doctor` on the
178+
machine that hosts the environment. It reports the database size and the
179+
space it can reclaim, then asks which repairs to run;
179180
pass `--fix` to run the recommended ones without a prompt (for scripts), or
180181
`--dry-run` to only report. An installed background service for the same data
181182
directory is stopped for the repair and started again afterwards, also when

0 commit comments

Comments
 (0)