From 31089adf7d4a268a8813fe128ad8060f821c06e3 Mon Sep 17 00:00:00 2001 From: pax Date: Thu, 9 Apr 2026 23:04:02 -0500 Subject: [PATCH] library: fix thumbnail lookup for templated filenames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Library thumbnails are saved by post_id (_copy_library_thumb uses f"{post.id}.jpg") but the library viewer looked them up by file stem (f"{filepath.stem}.jpg"). For digit-stem files (12345.jpg) these are the same. For templated files (artist_12345.jpg) the stem is "artist_12345" which doesn't match the thumbnail named "12345.jpg" — wrong or missing thumbnails. Fix: resolve post_id from the filename via get_library_post_id_by_filename, then look up the thumbnail as f"{post_id}.jpg". Generated thumbnails (for files without a cached browse thumbnail) also store by post_id now, so everything stays consistent. --- booru_viewer/gui/library.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/booru_viewer/gui/library.py b/booru_viewer/gui/library.py index 4dc6c13..bbe04c1 100644 --- a/booru_viewer/gui/library.py +++ b/booru_viewer/gui/library.py @@ -189,7 +189,17 @@ class LibraryView(QWidget): thumb._cached_path = str(filepath) thumb.setToolTip(filepath.name) thumb.set_saved_locally(True) - cached_thumb = lib_thumb_dir / f"{filepath.stem}.jpg" + # Thumbnails are stored by post_id (from _copy_library_thumb), + # not by filename stem. Resolve post_id so templated filenames + # like artist_12345.jpg find their thumbnail correctly. + thumb_name = filepath.stem # default: digit-stem fallback + if self._db: + pid = self._db.get_library_post_id_by_filename(filepath.name) + if pid is not None: + thumb_name = str(pid) + elif filepath.stem.isdigit(): + thumb_name = filepath.stem + cached_thumb = lib_thumb_dir / f"{thumb_name}.jpg" if cached_thumb.exists(): pix = QPixmap(str(cached_thumb)) if not pix.isNull():