Reworking file refresh button to only disable when global refresh is running.

This commit is contained in:
Roland 2026-02-14 17:17:08 -07:00
parent 0e5c977471
commit c216e8ed26
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 38 additions and 16 deletions

View file

@ -61,7 +61,6 @@ import {SelectableTable} from "./Tables";
import {VideoCard, VideoRowCells} from "./Videos";
import {FileBrowser} from "./FileBrowser";
import {refreshFiles} from "../api";
import {useSubscribeEventName} from "../Events";
import {TagsSelector} from "../Tags";
import {Headlines} from "./Headline";
import {useSearch} from "./Search";
@ -735,35 +734,54 @@ export function FilesRoute() {
}
const useRefresh = () => {
const refreshing = useStatusFlag('file_worker_busy');
const refreshingDirectory = useStatusFlag('refreshing_directory');
const wrolModeEnabled = useWROLMode();
const globalRefreshActive = useStatusFlag('global_refresh_active');
const [loading, setLoading] = React.useState(false);
const [globalRefreshLoading, setGlobalRefreshLoading] = React.useState(false);
const prevGlobalRefreshActive = React.useRef(false);
const localRefreshFiles = async (paths) => {
setLoading(true);
await refreshFiles(paths);
try {
await refreshFiles(paths);
// Check if this was a global refresh (no paths = refresh all)
// If so, set globalRefreshLoading and schedule a fallback timeout
if (!paths || paths.length === 0) {
setGlobalRefreshLoading(true);
setTimeout(() => {
setGlobalRefreshLoading(false);
}, 10000);
}
} finally {
setLoading(false);
}
}
// Clear loading when global refresh event completes.
useSubscribeEventName('refresh_completed', () => setLoading(false));
// Clear globalRefreshLoading when flag transitions from true to false
React.useEffect(() => {
if (prevGlobalRefreshActive.current && !globalRefreshActive) {
setGlobalRefreshLoading(false);
}
prevGlobalRefreshActive.current = globalRefreshActive;
}, [globalRefreshActive]);
const isGlobalRefreshing = globalRefreshLoading || globalRefreshActive;
return {
refreshing,
refreshingDirectory,
wrolModeEnabled,
globalRefreshing: isGlobalRefreshing,
loading,
wrolModeEnabled,
refreshFiles: localRefreshFiles,
}
}
export function FilesRefreshButton({paths}) {
const {refreshing, refreshingDirectory, wrolModeEnabled, loading, refreshFiles} = useRefresh();
const {globalRefreshing, loading, wrolModeEnabled, refreshFiles} = useRefresh();
return <Button icon='refresh'
loading={loading || refreshing || refreshingDirectory}
loading={loading || globalRefreshing}
onClick={() => refreshFiles(paths)}
disabled={wrolModeEnabled || loading || refreshing}/>
disabled={wrolModeEnabled || globalRefreshing}/>
;
}

View file

@ -1049,7 +1049,6 @@ async def test_global_refresh_sends_global_events(
events_fixture.assert_has_event('global_refresh_modeling_completed')
events_fixture.assert_has_event('global_refresh_indexing_completed')
events_fixture.assert_has_event('global_after_refresh_completed')
events_fixture.assert_has_event('refresh_completed')
# Should NOT send directory_refresh or files_refreshed
events_fixture.assert_no_event('directory_refresh')

View file

@ -1097,6 +1097,7 @@ class FileWorker:
if is_global_refresh:
global_refresh_start_time = time.time()
logger.info(f'Starting global refresh with {task.count} files')
flags.global_refresh_active.set()
Events.send_global_refresh_started()
elif dir_paths and len(dir_paths) == 1 and not file_paths:
relative_path = self._get_relative_path(dir_paths[0])
@ -1108,8 +1109,6 @@ class FileWorker:
# Process files and directories within discovery flag context
# This covers comparing, upserting, and deleting phases
file_result = None
dir_result = None
with flags.file_worker_discovery:
# Process files directly (fast path)
@ -1195,6 +1194,7 @@ class FileWorker:
# Set refresh_complete flag only when refreshing the entire media directory
if is_global_refresh:
flags.refresh_complete.set()
flags.global_refresh_active.clear()
# Mark job as complete if tracking
self._complete_job(task.job_id)

View file

@ -122,6 +122,9 @@ file_worker_modeling = Flag('file_worker_modeling')
file_worker_indexing = Flag('file_worker_indexing')
file_worker_cleanup = Flag('file_worker_cleanup')
# A global refresh is currently running.
global_refresh_active = Flag('global_refresh_active')
# The global refresh has been performed. This is False on a fresh instance of WROLPi.
refresh_complete = Flag('refresh_complete', store_db=True)
@ -136,6 +139,7 @@ def get_flags() -> dict:
file_worker_discovery=file_worker_discovery.is_set(),
file_worker_indexing=file_worker_indexing.is_set(),
file_worker_modeling=file_worker_modeling.is_set(),
global_refresh_active=global_refresh_active.is_set(),
have_internet=have_internet.is_set(),
map_importing=map_importing.is_set(),
outdated_zims=outdated_zims.is_set(),

View file

@ -93,6 +93,7 @@ class FlagsStatusResponse:
file_worker_discovery: bool
file_worker_indexing: bool
file_worker_modeling: bool
global_refresh_active: bool
have_internet: bool
map_importing: bool
outdated_zims: bool