fix pipe
This commit is contained in:
@@ -163,13 +163,25 @@ class LocalLibraryDB:
|
||||
# Use check_same_thread=False to allow multi-threaded access
|
||||
# This is safe because we're not sharing connections across threads;
|
||||
# each thread will get its own cursor
|
||||
self.connection = sqlite3.connect(str(self.db_path), check_same_thread=False)
|
||||
# Set a generous timeout to avoid "database is locked" errors during heavy concurrency
|
||||
self.connection = sqlite3.connect(str(self.db_path), check_same_thread=False, timeout=60.0)
|
||||
self.connection.row_factory = sqlite3.Row
|
||||
|
||||
# Enable Write-Ahead Logging (WAL) for better concurrency
|
||||
self.connection.execute("PRAGMA journal_mode=WAL")
|
||||
# Enable foreign keys
|
||||
self.connection.execute("PRAGMA foreign_keys = ON")
|
||||
|
||||
self._create_tables()
|
||||
logger.info(f"Database initialized at {self.db_path}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to initialize database: {e}", exc_info=True)
|
||||
if self.connection:
|
||||
try:
|
||||
self.connection.close()
|
||||
except Exception:
|
||||
pass
|
||||
self.connection = None
|
||||
raise
|
||||
|
||||
def _create_tables(self) -> None:
|
||||
@@ -1492,6 +1504,19 @@ class LocalLibrarySearchOptimizer:
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get playlist ID {playlist_id}: {e}")
|
||||
return None
|
||||
|
||||
def delete_playlist(self, playlist_id: int) -> bool:
|
||||
"""Delete a playlist by ID."""
|
||||
if not self.db:
|
||||
return False
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("DELETE FROM playlists WHERE id = ?", (playlist_id,))
|
||||
self.db.connection.commit()
|
||||
return cursor.rowcount > 0
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to delete playlist ID {playlist_id}: {e}")
|
||||
return False
|
||||
if not self.db:
|
||||
return []
|
||||
return self.db.search_by_tag(tag, limit)
|
||||
|
||||
Reference in New Issue
Block a user