From 3e5f83b0ac7c25958f7f85b018aa4dee4df0d543 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 15 Apr 2026 05:11:06 +0000 Subject: [PATCH 1/2] fix: set status to idle before finalization on "Nothing to do" path When all files are already processed (total == 0), the scan takes an early return through _finalize_scan() without first updating the UI status to "idle". Because _finalize_scan() can spend minutes resolving Lidarr IDs for existing corrupt files, the UI keeps showing "Scanning" long after logs say "Nothing to do." Mirror the idle update already present on the normal scan completion path (line 773) so the status dot turns green immediately. https://claude.ai/code/session_01TiRDfaCYdz46ofc1SwTg8v --- beats_check.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beats_check.py b/beats_check.py index a47a946..b54236b 100644 --- a/beats_check.py +++ b/beats_check.py @@ -603,6 +603,9 @@ def _run_scan_inner(input_folder, output_folder, log_file, log_dir, if total == 0: logger.debug("Nothing to do.") + # Mark idle before finalization — Lidarr ID resolution can take minutes + if _webui_app_state is not None: + _webui_app_state.update(status="idle", scan_progress=None) existing_details = _load_json( os.path.join(log_dir, "corrupt_details.json")) _finalize_scan(log_dir, corrupt_list_path, existing_details, From 87450e7d07571a530849012a52cd0c129826c5c6 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 15 Apr 2026 05:33:13 +0000 Subject: [PATCH 2/2] refactor: extract _handle_nothing_to_do to fix lint complexity Extracting the "Nothing to do" early-return block into its own helper brings _run_scan_inner back under the max-complexity=25 threshold. https://claude.ai/code/session_01TiRDfaCYdz46ofc1SwTg8v --- beats_check.py | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/beats_check.py b/beats_check.py index b54236b..313e3b9 100644 --- a/beats_check.py +++ b/beats_check.py @@ -571,6 +571,32 @@ def _finalize_scan(log_dir, corrupt_list_path, corrupt_details, logger.info("Review with: cat %s", corrupt_list_path) +def _handle_nothing_to_do(log_dir, corrupt_list_path, output_folder, + all_files, total_library_size, mode, + lidarr_url, lidarr_api_key): + """Fast path when every file has already been processed.""" + logger.debug("Nothing to do.") + # Mark idle before finalization — Lidarr ID resolution can take minutes + if _webui_app_state is not None: + _webui_app_state.update(status="idle", scan_progress=None) + existing_details = _load_json( + os.path.join(log_dir, "corrupt_details.json")) + _finalize_scan(log_dir, corrupt_list_path, existing_details, + output_folder, { + "version": __version__, + "finished": time.strftime('%Y-%m-%d %H:%M:%S'), + "duration": "0s", + "library_files": len(all_files), + "library_size": total_library_size, + "library_size_human": format_size(total_library_size), + "files_checked": 0, + "corrupted": 0, + "corrupt_size": 0, + "corrupt_size_human": format_size(0), + "mode": mode, + }, lidarr_url, lidarr_api_key) + + def _run_scan_inner(input_folder, output_folder, log_file, log_dir, mode, workers, corrupt_list_path, min_age_minutes, lidarr_url=None, lidarr_api_key=None): @@ -602,26 +628,9 @@ def _run_scan_inner(input_folder, output_folder, log_file, log_dir, if lidarr_url and lidarr_api_key else None) if total == 0: - logger.debug("Nothing to do.") - # Mark idle before finalization — Lidarr ID resolution can take minutes - if _webui_app_state is not None: - _webui_app_state.update(status="idle", scan_progress=None) - existing_details = _load_json( - os.path.join(log_dir, "corrupt_details.json")) - _finalize_scan(log_dir, corrupt_list_path, existing_details, - output_folder, { - "version": __version__, - "finished": time.strftime('%Y-%m-%d %H:%M:%S'), - "duration": "0s", - "library_files": len(all_files), - "library_size": total_library_size, - "library_size_human": format_size(total_library_size), - "files_checked": 0, - "corrupted": 0, - "corrupt_size": 0, - "corrupt_size_human": format_size(0), - "mode": mode, - }, lidarr_url, lidarr_api_key) + _handle_nothing_to_do(log_dir, corrupt_list_path, output_folder, + all_files, total_library_size, mode, + lidarr_url, lidarr_api_key) return 0 checked = 0