feat: add immediate cache refresh after scan completion and exclude pending items from missing German detection to prevent showing unscanned files

Call refresh_library_cache() after scan completion to immediately publish scanned metadata. Add needs_missing_scan check that only triggers missing scan when German review candidates exist without German tracks. Filter out pending items from missing_german_movies/missing_german_series to prevent showing unscanned files as missing German while background scanner processes them
This commit is contained in:
2026-08-26 13:47:24 +02:00
parent 3f418bb2a3
commit de0d360a3c
+14 -3
View File
@@ -1021,6 +1021,8 @@ def start_scan(source, force=False, rows_snapshot=None, series_snapshot=None):
future.result() future.result()
with job_lock: jobs[source]["done"] += 1 with job_lock: jobs[source]["done"] += 1
with job_lock: jobs[source]["state"] = "done" with job_lock: jobs[source]["state"] = "done"
# Publish the newly scanned metadata immediately to the cache.
refresh_library_cache()
except Exception as exc: except Exception as exc:
log.error("%s-Scan fehlgeschlagen: %s", source, error_summary(exc)); jobs[source]["error"] = str(exc); jobs[source]["state"] = "error" log.error("%s-Scan fehlgeschlagen: %s", source, error_summary(exc)); jobs[source]["error"] = str(exc); jobs[source]["state"] = "error"
executor.submit(work) executor.submit(work)
@@ -1054,7 +1056,14 @@ def refresh_library_cache():
start_scan("radarr", force=True, rows_snapshot=rows) start_scan("radarr", force=True, rows_snapshot=rows)
if series and any(row.get("pending") for group in series for row in group["episodes"]): if series and any(row.get("pending") for group in series for row in group["episodes"]):
start_scan("sonarr", force=True, series_snapshot=series) start_scan("sonarr", force=True, series_snapshot=series)
if rows or series: needs_missing_scan = any(
row.get("local_path") != "" and is_german_review_candidate(row) and not has_german_track(row)
for row in rows
) or any(
episode.get("local_path") != "" and is_german_review_candidate(episode) and not has_german_track(episode)
for group in series for episode in group["episodes"]
)
if needs_missing_scan:
start_scan("missing", force=True, rows_snapshot=rows, series_snapshot=series) start_scan("missing", force=True, rows_snapshot=rows, series_snapshot=series)
log.info("Bibliotheks-Sync abgeschlossen: %s Filme, %s Serien", len(rows), len(series)) log.info("Bibliotheks-Sync abgeschlossen: %s Filme, %s Serien", len(rows), len(series))
@@ -1079,10 +1088,12 @@ def index():
rows = list(library_cache["rows"]) rows = list(library_cache["rows"])
series = list(library_cache["series"]) series = list(library_cache["series"])
error = library_cache["error"] error = library_cache["error"]
missing_german_movies = [row for row in rows if is_german_review_candidate(row) and not has_german_track(row)] # Unscanned files have no language information yet and must not be shown
# as missing German while the background scanner is still processing them.
missing_german_movies = [row for row in rows if is_german_review_candidate(row) and not row.get("pending") and not has_german_track(row)]
missing_german_series = [] missing_german_series = []
for group in series: for group in series:
episodes = [episode for episode in group["episodes"] if is_german_review_candidate(episode) and not has_german_track(episode)] episodes = [episode for episode in group["episodes"] if is_german_review_candidate(episode) and not episode.get("pending") and not has_german_track(episode)]
if episodes: if episodes:
missing_german_series.append({**group, "episodes": episodes}) missing_german_series.append({**group, "episodes": episodes})
series_categories = [ series_categories = [