Remove calls to pdb.commit(). Let @transaction do it.

This commit is contained in:
voussoir 2020-02-19 22:58:21 -08:00
parent 203fb9e00f
commit 8c797024e0
2 changed files with 0 additions and 99 deletions

View file

@ -113,17 +113,11 @@ class GroupableMixin:
self.photodb._cached_frozen_children = None
if commit:
self.photodb.commit(message='add to group')
@decorators.transaction
def add_children(self, members, *, commit=False):
for member in members:
self.add_child(member)
if commit:
self.photodb.commit(message='add multiple to group')
def assert_same_type(self, other):
if not isinstance(other, type(self)):
raise TypeError(f'Object must be of type {type(self)}, not {type(other)}.')
@ -155,8 +149,6 @@ class GroupableMixin:
# issues of recursion.
self.photodb.sql_delete(table=self.group_table, pairs={'memberid': self.id})
self._uncache()
if commit:
self.photodb.commit(message='delete tag')
def get_children(self):
child_rows = self.photodb.sql_select(
@ -209,9 +201,6 @@ class GroupableMixin:
self.photodb.sql_delete(table=self.group_table, pairs=pairs)
self.photodb._cached_frozen_children = None
if commit:
self.photodb.commit(message='remove from group')
def walk_children(self):
yield self
for child in self.get_children():
@ -316,9 +305,6 @@ class Album(ObjectBase, GroupableMixin):
data = {'albumid': self.id, 'directory': path.absolute_path}
self.photodb.sql_insert(table='album_associated_directories', data=data)
if commit:
self.photodb.commit(message='add associated directory')
def _add_photo(self, photo):
self.photodb.log.debug('Adding photo %s to %s', photo, self)
data = {'albumid': self.id, 'photoid': photo.id}
@ -332,9 +318,6 @@ class Album(ObjectBase, GroupableMixin):
self._add_photo(photo)
if commit:
self.photodb.commit(message='add photo to album')
@decorators.required_feature('album.edit')
@decorators.transaction
def add_photos(self, photos, *, commit=False):
@ -345,9 +328,6 @@ class Album(ObjectBase, GroupableMixin):
for photo in photos:
self._add_photo(photo)
if commit:
self.photodb.commit(message='add photos to album')
# Photo.add_tag already has @required_feature
@decorators.transaction
def add_tag_to_all(self, tag, *, nested_children=True, commit=False):
@ -368,9 +348,6 @@ class Album(ObjectBase, GroupableMixin):
for photo in photos:
photo.add_tag(tag)
if commit:
self.photodb.commit(message='add tag to all')
@decorators.required_feature('album.edit')
@decorators.transaction
def delete(self, *, delete_children=False, commit=False):
@ -380,8 +357,6 @@ class Album(ObjectBase, GroupableMixin):
self.photodb.sql_delete(table='album_photo_rel', pairs={'albumid': self.id})
self.photodb.sql_delete(table='albums', pairs={'id': self.id})
self._uncache()
if commit:
self.photodb.commit(message='delete album')
@property
def display_name(self):
@ -412,9 +387,6 @@ class Album(ObjectBase, GroupableMixin):
}
self.photodb.sql_update(table='albums', pairs=data, where_key='id')
if commit:
self.photodb.commit(message='edit album')
def get_associated_directories(self):
directory_rows = self.photodb.sql_select(
'SELECT directory FROM album_associated_directories WHERE albumid == ?',
@ -500,9 +472,6 @@ class Album(ObjectBase, GroupableMixin):
def remove_photo(self, photo, *, commit=False):
self._remove_photo(photo)
if commit:
self.photodb.commit(message='remove photo from album')
@decorators.required_feature('album.edit')
@decorators.transaction
def remove_photos(self, photos, *, commit=False):
@ -513,9 +482,6 @@ class Album(ObjectBase, GroupableMixin):
for photo in photos:
self._remove_photo(photo)
if commit:
self.photodb.commit(message='remove photos from album')
def sum_bytes(self, recurse=True):
query = '''
SELECT SUM(bytes) FROM photos
@ -616,8 +582,6 @@ class Bookmark(ObjectBase):
def delete(self, *, commit=False):
self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id})
self._uncache()
if commit:
self.photodb.commit()
@decorators.required_feature('bookmark.edit')
@decorators.transaction
@ -641,9 +605,6 @@ class Bookmark(ObjectBase):
}
self.photodb.sql_update(table='bookmarks', pairs=data, where_key='id')
if commit:
self.photodb.commit(message='edit bookmark')
class Photo(ObjectBase):
'''
@ -741,8 +702,6 @@ class Photo(ObjectBase):
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
if commit:
self.photodb.commit(message='add photo tag')
return tag
@property
@ -766,8 +725,6 @@ class Photo(ObjectBase):
'''
for tag in other_photo.get_tags():
self.add_tag(tag)
if commit:
self.photodb.commit(message='copy tags')
@decorators.required_feature('photo.edit')
@decorators.transaction
@ -788,8 +745,6 @@ class Photo(ObjectBase):
queue_action = {'action': os.remove, 'args': [path]}
self.photodb.on_commit_queue.append(queue_action)
self._uncache()
if commit:
self.photodb.commit(message='delete photo')
@property
def duration_string(self):
@ -849,8 +804,6 @@ class Photo(ObjectBase):
self.thumbnail = return_filepath
self._uncache()
if commit:
self.photodb.commit(message='generate thumbnail')
self.__reinit__()
return self.thumbnail
@ -988,8 +941,6 @@ class Photo(ObjectBase):
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self._uncache()
if commit:
self.photodb.commit(message='reload metadata')
@decorators.required_feature('photo.edit')
@decorators.transaction
@ -1018,8 +969,6 @@ class Photo(ObjectBase):
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self._uncache()
if commit:
self.photodb.commit(message='relocate photo')
@decorators.required_feature('photo.add_remove_tag')
@decorators.transaction
@ -1039,9 +988,6 @@ class Photo(ObjectBase):
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
if commit:
self.photodb.commit(message='remove photo tag')
@decorators.required_feature('photo.edit')
@decorators.transaction
def rename_file(self, new_filename, *, move=False, commit=False):
@ -1117,9 +1063,6 @@ class Photo(ObjectBase):
self.searchhidden = searchhidden
if commit:
self.photodb.commit(message='set searchhidden')
@decorators.required_feature('photo.edit')
@decorators.transaction
def set_override_filename(self, new_filename, *, commit=False):
@ -1136,9 +1079,6 @@ class Photo(ObjectBase):
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
if commit:
self.photodb.commit(message='set override filename')
self.__reinit__()
@ -1236,9 +1176,6 @@ class Tag(ObjectBase, GroupableMixin):
}
self.photodb.sql_insert(table='tag_synonyms', data=data)
if commit:
self.photodb.commit(message='add synonym')
return synname
@decorators.required_feature('tag.edit')
@ -1303,8 +1240,6 @@ class Tag(ObjectBase, GroupableMixin):
# Enjoy your new life as a monk.
mastertag.add_synonym(self.name)
if commit:
self.photodb.commit(message='convert to synonym')
@decorators.required_feature('tag.edit')
@decorators.transaction
@ -1316,8 +1251,6 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.sql_delete(table='tag_synonyms', pairs={'mastername': self.name})
self.photodb.sql_delete(table='tags', pairs={'id': self.id})
self._uncache()
if commit:
self.photodb.commit(message='delete tag')
@decorators.required_feature('tag.edit')
@decorators.transaction
@ -1337,8 +1270,6 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.sql_update(table='tags', pairs=data, where_key='id')
self._uncache()
if commit:
self.photodb.commit(message='edit tag')
def get_synonyms(self):
syn_rows = self.photodb.sql_select(
@ -1381,9 +1312,6 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb._cached_frozen_children = None
self.photodb.sql_delete(table='tag_synonyms', pairs={'name': synname})
if commit:
self.photodb.commit(message='remove synonym')
@decorators.required_feature('tag.edit')
@decorators.transaction
def rename(self, new_name, *, apply_to_synonyms=True, commit=False):
@ -1418,8 +1346,6 @@ class Tag(ObjectBase, GroupableMixin):
self.name = new_name
self._uncache()
if commit:
self.photodb.commit(message='rename tag')
class User(ObjectBase):
@ -1486,9 +1412,6 @@ class User(ObjectBase):
self._display_name = display_name
if commit:
self.photodb.commit(message='set display name')
class WarningBag:
def __init__(self):

View file

@ -116,8 +116,6 @@ class PDBAlbumMixin:
photos = [self.get_photo(photo) for photo in photos]
album.add_photos(photos)
if commit:
self.commit(message='new album')
return album
@ -157,8 +155,6 @@ class PDBBookmarkMixin:
bookmark = self.get_cached_instance('bookmark', data)
if commit:
self.commit(message='new bookmark')
return bookmark
@ -278,8 +274,6 @@ class PDBPhotoMixin:
for tag in tags:
photo.add_tag(tag)
if commit:
self.commit(message='new photo')
return photo
@decorators.transaction
@ -299,9 +293,6 @@ class PDBPhotoMixin:
continue
photo.delete()
if commit:
self.commit(message='purge deleted photos')
@decorators.transaction
def purge_empty_albums(self, albums=None, *, commit=False):
if albums is None:
@ -319,9 +310,6 @@ class PDBPhotoMixin:
to_check.update(album.get_parents())
album.delete()
if commit:
self.commit(message='purge empty albums')
def search(
self,
*,
@ -940,8 +928,6 @@ class PDBTagMixin:
tag = self.get_cached_instance('tag', data)
if commit:
self.commit(message='new tag')
return tag
def normalize_tagname(self, tagname):
@ -1104,9 +1090,6 @@ class PDBUserMixin:
}
self.sql_insert(table='users', data=data)
if commit:
self.commit(message='register user')
return self.get_cached_instance('user', data)
@ -1237,9 +1220,6 @@ class PDBUtilMixin:
current_album.add_photos(photos)
if commit:
self.commit(message='digest directory')
if make_albums:
return main_album
else:
@ -1289,8 +1269,6 @@ class PDBUtilMixin:
note = ('new_synonym', f'{tag.name}+{synonym}')
output_notes.append(note)
if commit:
self.commit(message='easybake')
return output_notes