Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat: suggest t3 doctor when the database has space to reclaim #19437

Mergedjuliusmarmingemerged 4 commits intot3/db-compaction-2-doctor fromrefs/pull/19437/headmerged by juliusmarminge View on GitHub

Showing 18 changed files with 80 additions and 0 deletions (loading 15).

x
0 of 18 viewed, 18 left
62 additions and 0 deletionsapps/mobile/src/features/settings/components/DatabaseStorageNotice.tsxAdded
View file
@@ -0,0 +1,62 @@
+import { useAtomSet, useAtomValue } from "@effect/atom-react";
+import { shouldRecommendDatabaseCompaction } from "@t3tools/contracts";
+import { AsyncResult } from "effect/reactivity";
+import { View } from "react-native";
+​
+import { AppText as Text } from "../../../components/ui/AppText";
+import { copyTextWithHaptic } from "../../../lib/copyTextWithHaptic";
+import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../../state/preferences";
+import { serverEnvironment } from "../../../state/server";
+import type { SettingsTarget } from "../settings-environment-filter";
+import { SettingsActionRow } from "./SettingsActionRow";
+import { SettingsSection } from "./SettingsSection";
+​
+/** Suggests `t3 doctor` for a database that still holds at least 1 GiB of freed pages. */
+export function DatabaseStorageNotice({ target }: { readonly target: SettingsTarget }) {
+ const result = useAtomValue(
+ serverEnvironment.databaseStorage({ environmentId: target.environmentId, input: {} }),
+ );
+ const preferences = useAtomValue(mobilePreferencesAtom);
+ const updatePreferences = useAtomSet(updateMobilePreferencesAtom);
+ const dismissed =
+ AsyncResult.isSuccess(preferences) &&
+ preferences.value.dismissedDatabaseStorageNotices?.includes(target.environmentId) === true;
+ const status = result._tag === "Success" ? result.value : null;
+ if (dismissed || status === null || !shouldRecommendDatabaseCompaction(status)) return null;
+ const gib = (status.reclaimableBytes / 1024 ** 3).toFixed(1);
+ return (
+ <SettingsSection title={`Reclaim ${gib} GiB on ${target.label}`}>
+ <View className="gap-3 p-4">
+ <Text className="text-sm text-muted-foreground">