Videre
This commit is contained in:
@@ -12,6 +12,12 @@ from pathlib import Path
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
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.observers import Observer
|
||||||
from watchdog.events import (
|
from watchdog.events import (
|
||||||
FileSystemEventHandler,
|
FileSystemEventHandler,
|
||||||
@@ -23,7 +29,6 @@ try:
|
|||||||
WATCHDOG_AVAILABLE = True
|
WATCHDOG_AVAILABLE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
WATCHDOG_AVAILABLE = False
|
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.tag_reader import is_supported, read_tags, get_file_modified_at
|
||||||
from local.local_db import (
|
from local.local_db import (
|
||||||
@@ -184,16 +189,26 @@ class LibraryWatcher:
|
|||||||
self._observer.schedule(handler, str(path), recursive=True)
|
self._observer.schedule(handler, str(path), recursive=True)
|
||||||
|
|
||||||
def _full_scan_all(self):
|
def _full_scan_all(self):
|
||||||
"""Kør fuld scan på alle aktive biblioteker — i baggrundstråde."""
|
"""Kør fuld scan på alle aktive biblioteker — én ad gangen i baggrundstråd."""
|
||||||
for lib in get_libraries(active_only=True):
|
def _run():
|
||||||
path = Path(lib["path"])
|
try:
|
||||||
if path.exists():
|
import sqlite3
|
||||||
t = threading.Thread(
|
from local.local_db import DB_PATH
|
||||||
target=self._full_scan_library,
|
conn = sqlite3.connect(str(DB_PATH))
|
||||||
args=(lib["id"], str(path)),
|
conn.row_factory = sqlite3.Row
|
||||||
daemon=True
|
libs = conn.execute(
|
||||||
)
|
"SELECT id, path FROM libraries WHERE is_active=1"
|
||||||
t.start()
|
).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):
|
def _full_scan_library(self, library_id: int, library_path: str):
|
||||||
"""Scan ét bibliotek med sin egen SQLite-forbindelse — blokerer aldrig GUI."""
|
"""Scan ét bibliotek med sin egen SQLite-forbindelse — blokerer aldrig GUI."""
|
||||||
|
|||||||
Reference in New Issue
Block a user