Add Album.remove_photos for batch removals.
This commit is contained in:
parent
698981dd29
commit
48396d6ab6
1 changed files with 22 additions and 6 deletions
|
@ -490,20 +490,36 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
result = super().leave_group(*args, **kwargs)
|
result = super().leave_group(*args, **kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@decorators.required_feature('album.edit')
|
def _remove_photo(self, photo):
|
||||||
@decorators.transaction
|
|
||||||
def remove_photo(self, photo, *, commit=True):
|
|
||||||
if not self.has_photo(photo):
|
|
||||||
return
|
|
||||||
|
|
||||||
self.photodb.log.debug('Removing photo %s from %s', photo, self)
|
self.photodb.log.debug('Removing photo %s from %s', photo, self)
|
||||||
pairs = {'albumid': self.id, 'photoid': photo.id}
|
pairs = {'albumid': self.id, 'photoid': photo.id}
|
||||||
self.photodb.sql_delete(table='album_photo_rel', pairs=pairs)
|
self.photodb.sql_delete(table='album_photo_rel', pairs=pairs)
|
||||||
|
|
||||||
|
@decorators.required_feature('album.edit')
|
||||||
|
@decorators.transaction
|
||||||
|
def remove_photo(self, photo, *, commit=True):
|
||||||
|
self._remove_photo(photo)
|
||||||
self._uncache_sums()
|
self._uncache_sums()
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - remove photo from album')
|
self.photodb.log.debug('Committing - remove photo from album')
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
||||||
|
@decorators.required_feature('album.edit')
|
||||||
|
@decorators.transaction
|
||||||
|
def remove_photos(self, photos, *, commit=True):
|
||||||
|
existing_photos = set(self.get_photos())
|
||||||
|
photos = set(photos)
|
||||||
|
photos = photos.intersection(existing_photos)
|
||||||
|
|
||||||
|
for photo in photos:
|
||||||
|
self._remove_photo(photo)
|
||||||
|
self._uncache_sums()
|
||||||
|
|
||||||
|
if commit:
|
||||||
|
self.photodb.log.debug('Committing - remove photos from album')
|
||||||
|
self.photodb.commit()
|
||||||
|
|
||||||
def sum_bytes(self, recurse=True):
|
def sum_bytes(self, recurse=True):
|
||||||
query = '''
|
query = '''
|
||||||
SELECT SUM(bytes) FROM photos
|
SELECT SUM(bytes) FROM photos
|
||||||
|
|
Loading…
Reference in a new issue