Add digest_directory parameter new_photo_ratelimit.

Initially inspired by the nuisance of having multiple photos
with the same timestamp because the system is too fast, this
feature could also be used to lessen disk load for running in
the background.
This commit is contained in:
voussoir 2018-03-10 14:18:28 -08:00
parent f04e055ca3
commit 9355cd09ef

View file

@ -20,6 +20,7 @@ from . import tag_export
from voussoirkit import cacheclass from voussoirkit import cacheclass
from voussoirkit import expressionmatch from voussoirkit import expressionmatch
from voussoirkit import pathclass from voussoirkit import pathclass
from voussoirkit import ratelimiter
from voussoirkit import spinal from voussoirkit import spinal
from voussoirkit import sqlhelpers from voussoirkit import sqlhelpers
@ -1192,6 +1193,7 @@ class PhotoDB(
exclude_filenames=None, exclude_filenames=None,
make_albums=True, make_albums=True,
new_photo_kwargs={}, new_photo_kwargs={},
new_photo_ratelimit=None,
recurse=True, recurse=True,
commit=True, commit=True,
): ):
@ -1208,6 +1210,8 @@ class PhotoDB(
photo = self.get_photo_by_path(filepath) photo = self.get_photo_by_path(filepath)
except exceptions.NoSuchPhoto: except exceptions.NoSuchPhoto:
photo = self.new_photo(filepath.absolute_path, commit=False, **new_photo_kwargs) photo = self.new_photo(filepath.absolute_path, commit=False, **new_photo_kwargs)
if new_photo_ratelimit is not None:
new_photo_ratelimit.limit()
photos.append(photo) photos.append(photo)
return photos return photos
@ -1242,6 +1246,9 @@ class PhotoDB(
if exclude_filenames is None: if exclude_filenames is None:
exclude_filenames = self.config['digest_exclude_files'] exclude_filenames = self.config['digest_exclude_files']
if isinstance(new_photo_ratelimit, (int, float)):
new_photo_ratelimit = ratelimiter.Ratelimiter(allowance=1, period=new_photo_ratelimit)
if 'commit' in new_photo_kwargs: if 'commit' in new_photo_kwargs:
new_photo_kwargs.pop('commit') new_photo_kwargs.pop('commit')
if 'filepath' in new_photo_kwargs: if 'filepath' in new_photo_kwargs: