From 9355cd09ef8483e2dd80e8b11b19566fbdff7d92 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 10 Mar 2018 14:18:28 -0800 Subject: [PATCH] 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. --- etiquette/photodb.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index e7f519e..daaf1fc 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -20,6 +20,7 @@ from . import tag_export from voussoirkit import cacheclass from voussoirkit import expressionmatch from voussoirkit import pathclass +from voussoirkit import ratelimiter from voussoirkit import spinal from voussoirkit import sqlhelpers @@ -1192,6 +1193,7 @@ class PhotoDB( exclude_filenames=None, make_albums=True, new_photo_kwargs={}, + new_photo_ratelimit=None, recurse=True, commit=True, ): @@ -1208,6 +1210,8 @@ class PhotoDB( photo = self.get_photo_by_path(filepath) except exceptions.NoSuchPhoto: 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) return photos @@ -1242,6 +1246,9 @@ class PhotoDB( if exclude_filenames is None: 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: new_photo_kwargs.pop('commit') if 'filepath' in new_photo_kwargs: