From 4087827e86801f642ddbe3aacd7dcd713b991d3b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 7 Jan 2021 19:25:47 -0800 Subject: [PATCH] Delete some old vars and slightly improve some clarity. --- etiquette/objects.py | 19 ++++++++++--------- frontends/etiquette_flask/backend/common.py | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 6575931..b79c35e 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -277,10 +277,6 @@ class Album(ObjectBase, GroupableMixin): self.group_getter_many = self.photodb.get_albums_by_id - self._sum_bytes_local = None - self._sum_bytes_recursive = None - self._sum_photos_recursive = None - def __repr__(self): return f'Album:{self.id}' @@ -374,9 +370,12 @@ class Album(ObjectBase, GroupableMixin): def add_photos(self, photos): existing_photos = set(self.get_photos()) photos = set(photos) - photos = photos.difference(existing_photos) + new_photos = photos.difference(existing_photos) - for photo in photos: + if not new_photos: + return + + for photo in new_photos: self._add_photo(photo) # Photo.add_tag already has @required_feature @@ -457,7 +456,6 @@ class Album(ObjectBase, GroupableMixin): return directories def get_photos(self): - photos = [] photo_rows = self.photodb.sql_select( 'SELECT photoid FROM album_photo_rel WHERE albumid == ?', [self.id] @@ -556,9 +554,12 @@ class Album(ObjectBase, GroupableMixin): def remove_photos(self, photos): existing_photos = set(self.get_photos()) photos = set(photos) - photos = photos.intersection(existing_photos) + remove_photos = photos.intersection(existing_photos) - for photo in photos: + if not remove_photos: + return + + for photo in remove_photos: self._remove_photo(photo) def sum_bytes(self, recurse=True): diff --git a/frontends/etiquette_flask/backend/common.py b/frontends/etiquette_flask/backend/common.py index 219c108..a36cc4f 100644 --- a/frontends/etiquette_flask/backend/common.py +++ b/frontends/etiquette_flask/backend/common.py @@ -64,6 +64,8 @@ file_etag_manager = client_caching.FileEtagManager( _original_route = site.route def decorate_and_route(*route_args, **route_kwargs): def wrapper(endpoint): + # Since a function might have multiple routes, we may be seeing the + # same one multiple times. The _fully_decorated will track that. if not hasattr(endpoint, '_fully_decorated'): endpoint = decorators.catch_etiquette_exception(endpoint) endpoint = session_manager.give_token(endpoint)