For sql_insert / _update, let default commit=False.

Because all the calls are using it that way anyway.
This commit is contained in:
voussoir 2018-02-17 14:01:12 -08:00
parent cd4e970f04
commit 9939f5da1d
2 changed files with 22 additions and 22 deletions

View file

@ -86,7 +86,7 @@ class GroupableMixin:
'parentid': self.id,
'memberid': member.id,
}
self.photodb.sql_insert(table=self.group_table, data=data, commit=False)
self.photodb.sql_insert(table=self.group_table, data=data)
self.photodb._cached_frozen_children = None
@ -285,7 +285,7 @@ class Album(ObjectBase, GroupableMixin):
'albumid': self.id,
'directory': filepath.absolute_path,
}
self.photodb.sql_insert(table='album_associated_directories', data=data, commit=False)
self.photodb.sql_insert(table='album_associated_directories', data=data)
if commit:
self.photodb.log.debug('Committing - add associated directory')
@ -304,7 +304,7 @@ class Album(ObjectBase, GroupableMixin):
'albumid': self.id,
'photoid': photo.id,
}
self.photodb.sql_insert(table='album_photo_rel', data=data, commit=False)
self.photodb.sql_insert(table='album_photo_rel', data=data)
self._uncache_sums()
if commit:
@ -376,7 +376,7 @@ class Album(ObjectBase, GroupableMixin):
'title': self.title,
'description': self.description,
}
self.photodb.sql_update(table='albums', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='albums', pairs=data, where_key='id')
if commit:
self.photodb.log.debug('Committing - edit album')
@ -525,7 +525,7 @@ class Bookmark(ObjectBase):
'title': self.title,
'url': self.url,
}
self.photodb.sql_update(table='bookmarks', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='bookmarks', pairs=data, where_key='id')
if commit:
self.photodb.log.debug('Committing - edit bookmark')
@ -623,12 +623,12 @@ class Photo(ObjectBase):
'photoid': self.id,
'tagid': tag.id
}
self.photodb.sql_insert(table='photo_tag_rel', data=data, commit=False)
self.photodb.sql_insert(table='photo_tag_rel', data=data)
data = {
'id': self.id,
'tagged_at': helpers.now(),
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
if commit:
self.photodb.log.debug('Committing - add photo tag')
@ -763,7 +763,7 @@ class Photo(ObjectBase):
'id': self.id,
'thumbnail': return_filepath,
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self.thumbnail = return_filepath
self._uncache()
@ -900,7 +900,7 @@ class Photo(ObjectBase):
'duration': self.duration,
'bytes': self.bytes,
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self._uncache()
if commit:
@ -937,7 +937,7 @@ class Photo(ObjectBase):
'id': self.id,
'filepath': new_filepath.absolute_path,
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self._uncache()
if commit:
@ -963,7 +963,7 @@ class Photo(ObjectBase):
'id': self.id,
'tagged_at': helpers.now(),
}
self.photodb.sql_update(table='photos', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='photos', pairs=data, where_key='id')
if commit:
self.photodb.log.debug('Committing - remove photo tag')
@ -1103,7 +1103,7 @@ class Tag(ObjectBase, GroupableMixin):
'name': synname,
'mastername': self.name,
}
self.photodb.sql_insert(table='tag_synonyms', data=data, commit=False)
self.photodb.sql_insert(table='tag_synonyms', data=data)
if commit:
self.photodb.log.debug('Committing - add synonym')
@ -1149,7 +1149,7 @@ class Tag(ObjectBase, GroupableMixin):
'photoid': photoid,
'tagid': mastertag.id,
}
self.photodb.sql_insert(table='photo_tag_rel', data=data, commit=False)
self.photodb.sql_insert(table='photo_tag_rel', data=data)
# Then delete the relationships with the old tag
self.delete()
@ -1190,7 +1190,7 @@ class Tag(ObjectBase, GroupableMixin):
'id': self.id,
'description': self.description
}
self.photodb.sql_update(table='tags', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='tags', pairs=data, where_key='id')
self._uncache()
if commit:
@ -1299,7 +1299,7 @@ class Tag(ObjectBase, GroupableMixin):
'id': self.id,
'name': new_name,
}
self.photodb.sql_update(table='tags', pairs=data, where_key='id', commit=False)
self.photodb.sql_update(table='tags', pairs=data, where_key='id')
cur = self.photodb.sql.cursor()
if apply_to_synonyms:

View file

@ -128,7 +128,7 @@ class PDBAlbumMixin:
'title': title,
'description': description,
}
self.sql_insert(table='albums', data=data, commit=False)
self.sql_insert(table='albums', data=data)
album = objects.Album(self, data)
@ -175,7 +175,7 @@ class PDBBookmarkMixin:
'title': title,
'url': url,
}
self.sql_insert(table='bookmarks', data=data, commit=False)
self.sql_insert(table='bookmarks', data=data)
bookmark = objects.Bookmark(self, data)
if commit:
@ -283,7 +283,7 @@ class PDBPhotoMixin:
'duration': None,
'thumbnail': None,
}
self.sql_insert(table='photos', data=data, commit=False)
self.sql_insert(table='photos', data=data)
photo = objects.Photo(self, data)
@ -748,7 +748,7 @@ class PDBTagMixin:
'name': tagname,
'description': description,
}
self.sql_insert(table='tags', data=data, commit=False)
self.sql_insert(table='tags', data=data)
if commit:
self.log.debug('Committing - new_tag')
@ -922,7 +922,7 @@ class PDBUserMixin:
'password': hashed_password,
'created': created,
}
self.sql_insert(table='users', data=data, commit=False)
self.sql_insert(table='users', data=data)
if commit:
self.log.debug('Committing - register user')
@ -1309,7 +1309,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
thing = thing_map['class'](self, db_row=thing)
yield thing
def sql_insert(self, table, data, *, commit=True):
def sql_insert(self, table, data, *, commit=False):
column_names = constants.SQL_COLUMNS[table]
cur = self.sql.cursor()
@ -1320,7 +1320,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
if commit:
self.commit()
def sql_update(self, table, pairs, where_key, *, commit=True):
def sql_update(self, table, pairs, where_key, *, commit=False):
cur = self.sql.cursor()
(query, bindings) = sqlhelpers.update_filler(pairs, where_key=where_key)