Move purge_empty_albums to PDBAlbumMixin.

This commit is contained in:
voussoir 2020-09-15 13:44:28 -07:00
parent adbdb3bdb4
commit 5bc3fdd08e

View file

@ -120,6 +120,23 @@ class PDBAlbumMixin:
return album return album
@decorators.transaction
def purge_empty_albums(self, albums=None):
if albums is None:
to_check = set(self.get_albums())
else:
to_check = set()
for album in albums:
to_check.update(album.walk_children())
while to_check:
album = to_check.pop()
if album.get_children() or album.get_photos():
continue
# This may have been the last child of an otherwise empty parent.
to_check.update(album.get_parents())
album.delete()
class PDBBookmarkMixin: class PDBBookmarkMixin:
def __init__(self): def __init__(self):
@ -486,23 +503,6 @@ class PDBPhotoMixin:
continue continue
photo.delete() photo.delete()
@decorators.transaction
def purge_empty_albums(self, albums=None):
if albums is None:
to_check = set(self.get_albums())
else:
to_check = set()
for album in albums:
to_check.update(album.walk_children())
while to_check:
album = to_check.pop()
if album.get_children() or album.get_photos():
continue
# This may have been the last child of an otherwise empty parent.
to_check.update(album.get_parents())
album.delete()
def search( def search(
self, self,
*, *,