perf(settings): only poll sync status while a scan is running

This commit is contained in:
fallenbagel
2026-07-31 04:37:25 +08:00
parent 6aebf6f593
commit 380d059a7a
2 changed files with 6 additions and 16 deletions

View File

@@ -86,11 +86,9 @@ interface SyncStatus {
interface SettingsJellyfinProps {
isSetupSettings?: boolean;
onComplete?: () => void;
}
const SettingsJellyfin: React.FC<SettingsJellyfinProps> = ({
onComplete,
isSetupSettings,
}) => {
const [isSyncing, setIsSyncing] = useState(false);
@@ -102,7 +100,7 @@ const SettingsJellyfin: React.FC<SettingsJellyfinProps> = ({
const { data: dataSync, mutate: revalidateSync } = useSWR<SyncStatus>(
'/api/v1/settings/jellyfin/sync',
{
refreshInterval: 1000,
refreshInterval: (latestData) => (latestData?.running ? 1000 : 0),
}
);
const intl = useIntl();
@@ -216,10 +214,6 @@ const SettingsJellyfin: React.FC<SettingsJellyfinProps> = ({
await axios.put(`/api/v1/settings/jellyfin/library/${libraryId}`, {
enabled: !activeLibraries.includes(libraryId),
});
if (onComplete) {
onComplete();
}
} catch {
addToast(intl.formatMessage(messages.toggleLibraryFailure), {
autoDismiss: true,

View File

@@ -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<PlexDevice[] | null>(
@@ -129,7 +129,7 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {
const { data: dataSync, mutate: revalidateSync } = useSWR<SyncStatus>(
'/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) => {
<p className="description">
{intl.formatMessage(messages.plexsettingsDescription)}
</p>
{!!onComplete && (
{isSetupSettings && (
<div className="section">
<Alert
title={intl.formatMessage(messages.settingUpPlexDescription, {
@@ -730,7 +726,7 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {
</div>
</div>
</div>
{!onComplete && (
{!isSetupSettings && (
<>
<div className="mb-6 mt-10">
<h3 className="heading">