From 54add8ad61ff2f03030a1d2fbfa3ee0917ad1be3 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 14 Sep 2020 05:16:24 -0700 Subject: [PATCH] Add search parameter yield_albums. The exact details of this feature are still experimental, but I think the concept is sound enough to make it an official parameter. --- etiquette/objects.py | 2 +- etiquette/photodb.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index f6f7f94..d434af5 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -835,7 +835,7 @@ class Photo(ObjectBase): [self.id] ) album_ids = [row[0] for row in album_ids] - albums = list(self.photodb.get_albums_by_id(album_ids)) + albums = set(self.photodb.get_albums_by_id(album_ids)) return albums def get_tags(self): diff --git a/etiquette/photodb.py b/etiquette/photodb.py index ab440eb..8462616 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -519,6 +519,8 @@ class PDBPhotoMixin: orderby=None, warning_bag=None, give_back_parameters=False, + + yield_albums=True, ): ''' PHOTO PROPERTIES @@ -611,6 +613,10 @@ class PDBPhotoMixin: If True, the generator's first yield will be a dictionary of all the cleaned up, normalized parameters. The user may have given us loads of trash, so we should show them the formatting we want. + + yield_albums: + If True, albums which contain photos matching the search will also + be returned. ''' start_time = time.time() @@ -837,10 +843,10 @@ class PDBPhotoMixin: if limit is not None and photos_received >= limit: break - for album in photo.get_containing_albums(): - if album not in seen_albums: - seen_albums.add(album) - yield album + if yield_albums: + new_albums = photo.get_containing_albums().difference(seen_albums) + yield from new_albums + seen_albums.update(new_albums) photos_received += 1 yield photo