diff options
| author | Warry <FunWarry@users.noreply.github.com> | 2025-11-29 12:10:06 +0100 |
|---|---|---|
| committer | Warry <FunWarry@users.noreply.github.com> | 2025-11-29 12:10:06 +0100 |
| commit | d2c3e8ab8f1dcaec2b8be7ff9d1fb6c0df2d5296 (patch) | |
| tree | 2cf51e324cca81e198758e57a1c6e5780627e255 /tidal_dl_ng/cache.py | |
| parent | 28a6fe5a7dbadc9532de228a539c47ec49ca4aa2 (diff) | |
| download | tidal-dl-ng-d2c3e8ab8f1dcaec2b8be7ff9d1fb6c0df2d5296.tar.gz | |
feat(hover): add track details preview on hover + fix all ruff violations
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
Diffstat (limited to 'tidal_dl_ng/cache.py')
| -rw-r--r-- | tidal_dl_ng/cache.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tidal_dl_ng/cache.py b/tidal_dl_ng/cache.py new file mode 100644 index 0000000..e9e28df --- /dev/null +++ b/tidal_dl_ng/cache.py @@ -0,0 +1,55 @@ +"""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) |
