This commit is contained in:
2026-01-14 21:53:07 -08:00
parent 4b324b1e8e
commit 5d63777dee
5 changed files with 146 additions and 116 deletions

View File

@@ -202,6 +202,8 @@ class API_folder_store:
DB_NAME = "medios-macina.db"
SCHEMA_VERSION = 4
# Global lock across all instances to prevent 'database is locked' during concurrent operations.
_shared_db_lock = RLock()
def __init__(self, library_root: Path):
"""Initialize the database at the library root.
@@ -212,10 +214,8 @@ class API_folder_store:
self.library_root = expand_path(library_root).resolve()
self.db_path = self.library_root / self.DB_NAME
self.connection: Optional[sqlite3.Connection] = None
# sqlite3 connections are not safe for concurrent use across threads.
# We intentionally keep a single connection per API_folder_store instance,
# so we must serialize all DB operations on that connection.
self._db_lock = RLock()
# Use the shared lock
self._db_lock = self._shared_db_lock
self._init_db()
def _normalize_input_path(self, file_path: Path) -> Path: