library: clean up library_meta on delete (templated + digit-stem)
The Library tab's single-delete and multi-delete context menu actions called .unlink() directly, bypassing delete_from_library entirely. They only extracted post_id from digit-stem filenames (int(stem) if stem.isdigit()), so templated files like artist_12345.jpg got deleted from disk but left orphan library_meta rows that made get_saved_post_ids lie forever. Fix: resolve post_id via db.get_library_post_id_by_filename first (handles templated filenames), fall back to int(stem) for legacy digit-stem files, then call db.remove_library_meta(post_id) after unlinking. Both single-delete and multi-delete paths are fixed. This was the last source of orphan library_meta rows. With this fix + the earlier delete_from_library cleanup, every deletion path in the app now cleans up its meta row: - Library tab single delete (this commit) - Library tab multi delete (this commit) - Browse/preview "Unsave from Library" (via delete_from_library) - Browse multi-select "Unsave All" (via delete_from_library) - Bookmarks "Unsave from Library" (via delete_from_library) - Bookmarks multi-select "Unsave All" (via delete_from_library)
This commit is contained in:
parent
912be0bc80
commit
403c099bed
@ -497,10 +497,14 @@ class LibraryView(QWidget):
|
|||||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||||
)
|
)
|
||||||
if reply == QMessageBox.StandardButton.Yes:
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
post_id = int(filepath.stem) if filepath.stem.isdigit() else None
|
post_id = self._db.get_library_post_id_by_filename(filepath.name)
|
||||||
|
if post_id is None and filepath.stem.isdigit():
|
||||||
|
post_id = int(filepath.stem)
|
||||||
filepath.unlink(missing_ok=True)
|
filepath.unlink(missing_ok=True)
|
||||||
lib_thumb = thumbnails_dir() / "library" / f"{filepath.stem}.jpg"
|
lib_thumb = thumbnails_dir() / "library" / f"{filepath.stem}.jpg"
|
||||||
lib_thumb.unlink(missing_ok=True)
|
lib_thumb.unlink(missing_ok=True)
|
||||||
|
if post_id is not None:
|
||||||
|
self._db.remove_library_meta(post_id)
|
||||||
self.refresh()
|
self.refresh()
|
||||||
if post_id is not None:
|
if post_id is not None:
|
||||||
self.files_deleted.emit([post_id])
|
self.files_deleted.emit([post_id])
|
||||||
@ -548,11 +552,15 @@ class LibraryView(QWidget):
|
|||||||
if reply == QMessageBox.StandardButton.Yes:
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
deleted_ids = []
|
deleted_ids = []
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.stem.isdigit():
|
post_id = self._db.get_library_post_id_by_filename(f.name)
|
||||||
deleted_ids.append(int(f.stem))
|
if post_id is None and f.stem.isdigit():
|
||||||
|
post_id = int(f.stem)
|
||||||
f.unlink(missing_ok=True)
|
f.unlink(missing_ok=True)
|
||||||
lib_thumb = thumbnails_dir() / "library" / f"{f.stem}.jpg"
|
lib_thumb = thumbnails_dir() / "library" / f"{f.stem}.jpg"
|
||||||
lib_thumb.unlink(missing_ok=True)
|
lib_thumb.unlink(missing_ok=True)
|
||||||
|
if post_id is not None:
|
||||||
|
self._db.remove_library_meta(post_id)
|
||||||
|
deleted_ids.append(post_id)
|
||||||
self.refresh()
|
self.refresh()
|
||||||
if deleted_ids:
|
if deleted_ids:
|
||||||
self.files_deleted.emit(deleted_ids)
|
self.files_deleted.emit(deleted_ids)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user