diff --git a/etiquette/constants.py b/etiquette/constants.py index 552a876..56c22b2 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -146,8 +146,8 @@ DEFAULT_DATADIR = '.\\_etiquette' DEFAULT_CONFIGURATION = { 'log_level': logging.DEBUG, - 'cache_size_album': 200, - 'cache_size_photo': 1000, + 'cache_size_album': 1000, + 'cache_size_photo': 100000, 'cache_size_tag': 1000, 'cache_size_user': 200, diff --git a/etiquette/objects.py b/etiquette/objects.py index 9460da5..97fa3d8 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -210,6 +210,8 @@ class Album(ObjectBase, GroupableMixin): self.description = db_row['description'] self.name = 'Album %s' % self.id self.group_getter = self.photodb.get_album + self._sum_bytes_photos = None + self._sum_bytes_albums = None def __hash__(self): return hash(self.id) @@ -324,12 +326,14 @@ class Album(ObjectBase, GroupableMixin): self.photodb.commit() def sum_bytes(self, recurse=True, string=False): - if recurse: - photos = self.walk_photos() - else: - photos = self.photos() + if self._sum_bytes_photos is None: + self._sum_bytes_photos = sum(photo.bytes for photo in self.photos()) + total = self._sum_bytes_photos - total = sum(photo.bytes for photo in photos) + if recurse: + if self._sum_bytes_albums is None: + self._sum_bytes_albums = sum(a.sum_bytes(recurse=True) for a in self.children()) + total += self._sum_bytes_albums if string: return bytestring.bytestring(total) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 3e30732..750f56c 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1410,6 +1410,17 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs if isinstance(thing_id, thing_map['class']): thing_id = thing_id.id + cache = { + 'album': self._album_cache, + 'photo': self._photo_cache, + 'tag': self._tag_cache, + }[thing_type] + try: + val = cache[thing_id] + return val + except KeyError: + pass + query = 'SELECT * FROM %s WHERE id == ?' % thing_map['table'] cur = self.sql.cursor() cur.execute(query, [thing_id]) @@ -1417,6 +1428,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs if thing is None: raise thing_map['exception'](thing_id) thing = thing_map['class'](self, thing) + cache[thing_id] = thing return thing def get_things(self, thing_type, orderby=None):