Let digest_directory act as a generator, yielding photos & albums.
This commit is contained in:
parent
37c784982a
commit
50ecc4c1c1
3 changed files with 20 additions and 8 deletions
|
@ -367,6 +367,10 @@ def remove_path_badchars(filepath, allowed=''):
|
||||||
filepath = filepath.replace('\\', os.sep)
|
filepath = filepath.replace('\\', os.sep)
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
def run_generator(g):
|
||||||
|
for x in g:
|
||||||
|
pass
|
||||||
|
|
||||||
def seconds_to_hms(seconds):
|
def seconds_to_hms(seconds):
|
||||||
'''
|
'''
|
||||||
Convert integer number of seconds to an hh:mm:ss string.
|
Convert integer number of seconds to an hh:mm:ss string.
|
||||||
|
|
|
@ -1344,6 +1344,8 @@ class PDBUtilMixin:
|
||||||
new_photo_kwargs={},
|
new_photo_kwargs={},
|
||||||
new_photo_ratelimit=None,
|
new_photo_ratelimit=None,
|
||||||
recurse=True,
|
recurse=True,
|
||||||
|
yield_albums=True,
|
||||||
|
yield_photos=True,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Walk the directory and create Photos for every file.
|
Walk the directory and create Photos for every file.
|
||||||
|
@ -1398,6 +1400,12 @@ class PDBUtilMixin:
|
||||||
recurse:
|
recurse:
|
||||||
If True, walk the whole directory tree. If False, only digest the
|
If True, walk the whole directory tree. If False, only digest the
|
||||||
photos from the given directory and not its subdirectories.
|
photos from the given directory and not its subdirectories.
|
||||||
|
|
||||||
|
yield_albums:
|
||||||
|
If True, yield Albums as they are processed, new or not.
|
||||||
|
|
||||||
|
yield_photos:
|
||||||
|
If True, yield Photos as they are processed, new or not.
|
||||||
'''
|
'''
|
||||||
def _normalize_directory(directory):
|
def _normalize_directory(directory):
|
||||||
directory = pathclass.Path(directory)
|
directory = pathclass.Path(directory)
|
||||||
|
@ -1486,9 +1494,7 @@ class PDBUtilMixin:
|
||||||
new_photo_kwargs = _normalize_new_photo_kwargs(new_photo_kwargs)
|
new_photo_kwargs = _normalize_new_photo_kwargs(new_photo_kwargs)
|
||||||
new_photo_ratelimit = _normalize_new_photo_ratelimit(new_photo_ratelimit)
|
new_photo_ratelimit = _normalize_new_photo_ratelimit(new_photo_ratelimit)
|
||||||
|
|
||||||
if make_albums:
|
|
||||||
albums_by_path = {}
|
albums_by_path = {}
|
||||||
main_album = create_or_fetch_current_albums(albums_by_path, directory)
|
|
||||||
|
|
||||||
walk_generator = spinal.walk_generator(
|
walk_generator = spinal.walk_generator(
|
||||||
directory,
|
directory,
|
||||||
|
@ -1504,6 +1510,9 @@ class PDBUtilMixin:
|
||||||
|
|
||||||
photos = create_or_fetch_photos(files, new_photo_kwargs=new_photo_kwargs)
|
photos = create_or_fetch_photos(files, new_photo_kwargs=new_photo_kwargs)
|
||||||
|
|
||||||
|
if yield_photos:
|
||||||
|
yield from photos
|
||||||
|
|
||||||
if not make_albums:
|
if not make_albums:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1513,10 +1522,8 @@ class PDBUtilMixin:
|
||||||
for album in current_albums:
|
for album in current_albums:
|
||||||
album.add_photos(photos)
|
album.add_photos(photos)
|
||||||
|
|
||||||
if make_albums:
|
if yield_albums:
|
||||||
return main_album
|
yield from current_albums
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def easybake(self, ebstring, author=None):
|
def easybake(self, ebstring, author=None):
|
||||||
|
|
|
@ -75,7 +75,8 @@ def post_album_remove_child(album_id):
|
||||||
def post_album_refresh_directories(album_id):
|
def post_album_refresh_directories(album_id):
|
||||||
album = common.P_album(album_id, response_type='json')
|
album = common.P_album(album_id, response_type='json')
|
||||||
for directory in album.get_associated_directories():
|
for directory in album.get_associated_directories():
|
||||||
common.P.digest_directory(directory, new_photo_ratelimit=0.1)
|
digest = common.P.digest_directory(directory, new_photo_ratelimit=0.1)
|
||||||
|
etiquette.helpers.run_generator(digest)
|
||||||
common.P.commit(message='refresh album directories endpoint')
|
common.P.commit(message='refresh album directories endpoint')
|
||||||
return jsonify.make_json_response({})
|
return jsonify.make_json_response({})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue