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.
This commit is contained in:
voussoir 2020-09-14 05:16:24 -07:00
parent cc34c4d189
commit 54add8ad61
2 changed files with 11 additions and 5 deletions

View file

@ -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):

View file

@ -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