Implement comprehensive track information display on hover and resolve all code quality issues to achieve complete ruff compliance. MAJOR FEATURES: - Track details preview on hover with rich metadata display - Async BPM fetching with loading indicator - Enhanced metadata utilities with fuzzy matching - TIDAL API extras integration FILES MODIFIED: 15+ files (core, UI, tests, docs) RUFF COMPLIANCE: 0 errors (89+ violations resolved) - Fixed E999 syntax error in metadata_utils.py - Refactored 10+ complex functions (C901) - Updated error handling (S110, S112, SIM105) - Modernized type hints (UP038) - Fixed naming conflicts (A001, F811) BUG FIXES: - Added missing _on_update_cover() method (11 test failures) - Fixed BPM display and async loading - Improved thread safety TESTING: 30 passed, 1 skipped DOCUMENTATION: Windows PowerShell support, tox troubleshooting
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Cache management for GUI - LRU caches for performance optimization."""
|
|
|
|
from PySide6 import QtCore, QtGui
|
|
|
|
|
|
class TrackExtrasCache:
|
|
"""Thread-safe LRU cache for track extra metadata."""
|
|
|
|
def __init__(self, max_size: int = 256):
|
|
self._lock = QtCore.QReadWriteLock()
|
|
self._data: dict[str, dict] = {}
|
|
self._order: list[str] = []
|
|
self._max_size = max_size
|
|
|
|
def get(self, track_id: str) -> dict | None:
|
|
"""Get cached extras for a track ID."""
|
|
with QtCore.QReadLocker(self._lock):
|
|
return self._data.get(track_id)
|
|
|
|
def set(self, track_id: str, extras: dict) -> None:
|
|
"""Cache extras for a track ID with LRU eviction."""
|
|
with QtCore.QWriteLocker(self._lock):
|
|
if track_id in self._data:
|
|
self._order.remove(track_id)
|
|
self._data[track_id] = extras
|
|
self._order.append(track_id)
|
|
if len(self._order) > self._max_size:
|
|
oldest = self._order.pop(0)
|
|
self._data.pop(oldest, None)
|
|
|
|
|
|
class CoverPixmapCache:
|
|
"""Thread-safe LRU cache for cover pixmaps to avoid re-downloading."""
|
|
|
|
def __init__(self, max_size: int = 100):
|
|
self._lock = QtCore.QReadWriteLock()
|
|
self._pixmaps: dict[str, QtGui.QPixmap] = {}
|
|
self._order: list[str] = []
|
|
self._max_size = max_size
|
|
|
|
def get(self, cover_url: str) -> QtGui.QPixmap | None:
|
|
"""Get cached pixmap for a cover URL."""
|
|
with QtCore.QReadLocker(self._lock):
|
|
return self._pixmaps.get(cover_url)
|
|
|
|
def set(self, cover_url: str, pixmap: QtGui.QPixmap) -> None:
|
|
"""Cache a pixmap with LRU eviction."""
|
|
with QtCore.QWriteLocker(self._lock):
|
|
if cover_url in self._pixmaps:
|
|
self._order.remove(cover_url)
|
|
self._pixmaps[cover_url] = pixmap
|
|
self._order.append(cover_url)
|
|
if len(self._order) > self._max_size:
|
|
oldest = self._order.pop(0)
|
|
self._pixmaps.pop(oldest, None)
|