This commit is contained in:
2026-04-12 11:38:21 +02:00
parent 99cab7be86
commit 88a3d2f67b

View File

@@ -12,7 +12,13 @@ from pathlib import Path
from typing import Callable
try:
from watchdog.observers import Observer
import sys
if sys.platform == "win32":
# WindowsApiObserver opretter en tråd per undermappe og løber tør
# for Windows handles ved store biblioteker — brug polling i stedet
from watchdog.observers.polling import PollingObserver as Observer
else:
from watchdog.observers import Observer
from watchdog.events import (
FileSystemEventHandler,
FileCreatedEvent,
@@ -23,7 +29,6 @@ try:
WATCHDOG_AVAILABLE = True
except ImportError:
WATCHDOG_AVAILABLE = False
print("Advarsel: watchdog ikke installeret — fil-overvågning deaktiveret")
from local.tag_reader import is_supported, read_tags, get_file_modified_at
from local.local_db import (
@@ -184,16 +189,26 @@ class LibraryWatcher:
self._observer.schedule(handler, str(path), recursive=True)
def _full_scan_all(self):
"""Kør fuld scan på alle aktive biblioteker — i baggrundstråde."""
for lib in get_libraries(active_only=True):
path = Path(lib["path"])
if path.exists():
t = threading.Thread(
target=self._full_scan_library,
args=(lib["id"], str(path)),
daemon=True
)
t.start()
"""Kør fuld scan på alle aktive biblioteker — én ad gangen i baggrundstråd."""
def _run():
try:
import sqlite3
from local.local_db import DB_PATH
conn = sqlite3.connect(str(DB_PATH))
conn.row_factory = sqlite3.Row
libs = conn.execute(
"SELECT id, path FROM libraries WHERE is_active=1"
).fetchall()
conn.close()
for lib in libs:
lib_path = Path(lib["path"])
if lib_path.exists():
self._full_scan_library(lib["id"], str(lib_path))
except Exception as e:
logger.error(f"_full_scan_all fejl: {e}")
# Kør i én baggrundstråd — undgår Windows handle-udmattelse
threading.Thread(target=_run, daemon=True).start()
def _full_scan_library(self, library_id: int, library_path: str):
"""Scan ét bibliotek med sin egen SQLite-forbindelse — blokerer aldrig GUI."""