From 380d059a7a13483bc82985e674cdc4e86e89a97a Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Fri, 31 Jul 2026 04:37:25 +0800 Subject: [PATCH] perf(settings): only poll sync status while a scan is running --- src/components/Settings/SettingsJellyfin.tsx | 8 +------- src/components/Settings/SettingsPlex.tsx | 14 +++++--------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/components/Settings/SettingsJellyfin.tsx b/src/components/Settings/SettingsJellyfin.tsx index 9f2a3d6b9..e9ff3bed4 100644 --- a/src/components/Settings/SettingsJellyfin.tsx +++ b/src/components/Settings/SettingsJellyfin.tsx @@ -86,11 +86,9 @@ interface SyncStatus { interface SettingsJellyfinProps { isSetupSettings?: boolean; - onComplete?: () => void; } const SettingsJellyfin: React.FC = ({ - onComplete, isSetupSettings, }) => { const [isSyncing, setIsSyncing] = useState(false); @@ -102,7 +100,7 @@ const SettingsJellyfin: React.FC = ({ const { data: dataSync, mutate: revalidateSync } = useSWR( '/api/v1/settings/jellyfin/sync', { - refreshInterval: 1000, + refreshInterval: (latestData) => (latestData?.running ? 1000 : 0), } ); const intl = useIntl(); @@ -216,10 +214,6 @@ const SettingsJellyfin: React.FC = ({ await axios.put(`/api/v1/settings/jellyfin/library/${libraryId}`, { enabled: !activeLibraries.includes(libraryId), }); - - if (onComplete) { - onComplete(); - } } catch { addToast(intl.formatMessage(messages.toggleLibraryFailure), { autoDismiss: true, diff --git a/src/components/Settings/SettingsPlex.tsx b/src/components/Settings/SettingsPlex.tsx index 1ea2b69c4..ea0b089bd 100644 --- a/src/components/Settings/SettingsPlex.tsx +++ b/src/components/Settings/SettingsPlex.tsx @@ -110,10 +110,10 @@ interface PresetServerDisplay { message?: string; } interface SettingsPlexProps { - onComplete?: () => void; + isSetupSettings?: boolean; } -const SettingsPlex = ({ onComplete }: SettingsPlexProps) => { +const SettingsPlex = ({ isSetupSettings }: SettingsPlexProps) => { const [isSyncing, setIsSyncing] = useState(false); const [isRefreshingPresets, setIsRefreshingPresets] = useState(false); const [availableServers, setAvailableServers] = useState( @@ -129,7 +129,7 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => { const { data: dataSync, mutate: revalidateSync } = useSWR( '/api/v1/settings/plex/sync', { - refreshInterval: 1000, + refreshInterval: (latestData) => (latestData?.running ? 1000 : 0), } ); const intl = useIntl(); @@ -315,10 +315,6 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => { await axios.put(`/api/v1/settings/plex/library/${libraryId}`, { enabled: !activeLibraries.includes(libraryId), }); - - if (onComplete) { - onComplete(); - } } catch { addToast(intl.formatMessage(messages.toggleLibraryFailure), { autoDismiss: true, @@ -346,7 +342,7 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {

{intl.formatMessage(messages.plexsettingsDescription)}

- {!!onComplete && ( + {isSetupSettings && (
{
- {!onComplete && ( + {!isSetupSettings && ( <>