Update status refreshing to have a better interval

This commit is contained in:
LukeGus
2025-08-31 23:41:05 -05:00
parent 2fe9c0f854
commit 25178928a0
2 changed files with 6 additions and 7 deletions

View File

@@ -97,13 +97,12 @@ export function Server({
if (currentHostConfig?.id && isVisible) { if (currentHostConfig?.id && isVisible) {
fetchStatus(); fetchStatus();
fetchMetrics(); fetchMetrics();
// Only poll when component is visible to reduce unnecessary connections
intervalId = window.setInterval(() => { intervalId = window.setInterval(() => {
if (isVisible) { if (isVisible) {
fetchStatus(); fetchStatus();
fetchMetrics(); fetchMetrics();
} }
}, 300_000); // 5 minutes instead of 10 seconds }, 300_000);
} }
return () => { return () => {
@@ -116,7 +115,6 @@ export function Server({
const leftMarginPx = sidebarState === 'collapsed' ? 16 : 8; const leftMarginPx = sidebarState === 'collapsed' ? 16 : 8;
const bottomMarginPx = 8; const bottomMarginPx = 8;
// Check if a file manager tab for this host is already open
const isFileManagerAlreadyOpen = React.useMemo(() => { const isFileManagerAlreadyOpen = React.useMemo(() => {
if (!currentHostConfig) return false; if (!currentHostConfig) return false;
return tabs.some((tab: any) => return tabs.some((tab: any) =>
@@ -172,7 +170,7 @@ export function Server({
}} }}
title="Refresh status and metrics" title="Refresh status and metrics"
> >
Refresh Refresh Status
</Button> </Button>
{currentHostConfig?.enableFileManager && ( {currentHostConfig?.enableFileManager && (
<Button <Button

View File

@@ -35,15 +35,15 @@ interface HostProps {
export function Host({host}: HostProps): React.ReactElement { export function Host({host}: HostProps): React.ReactElement {
const {addTab} = useTabs(); const {addTab} = useTabs();
const [serverStatus, setServerStatus] = useState<'online' | 'offline'>('offline'); const [serverStatus, setServerStatus] = useState<'online' | 'offline' | 'degraded'>('degraded');
const tags = Array.isArray(host.tags) ? host.tags : []; const tags = Array.isArray(host.tags) ? host.tags : [];
const hasTags = tags.length > 0; const hasTags = tags.length > 0;
const title = host.name?.trim() ? host.name : `${host.username}@${host.ip}:${host.port}`; const title = host.name?.trim() ? host.name : `${host.username}@${host.ip}:${host.port}`;
useEffect(() => { useEffect(() => {
let cancelled = false;
let intervalId: number | undefined; let intervalId: number | undefined;
let cancelled = false;
const fetchStatus = async () => { const fetchStatus = async () => {
try { try {
@@ -57,7 +57,8 @@ export function Host({host}: HostProps): React.ReactElement {
}; };
fetchStatus(); fetchStatus();
intervalId = window.setInterval(fetchStatus, 60_000);
intervalId = window.setInterval(fetchStatus, 30000);
return () => { return () => {
cancelled = true; cancelled = true;