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, 'parentid': self.id,
'memberid': member.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 self.photodb._cached_frozen_children = None
@ -285,7 +285,7 @@ class Album(ObjectBase, GroupableMixin):
'albumid': self.id, 'albumid': self.id,
'directory': filepath.absolute_path, '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: if commit:
self.photodb.log.debug('Committing - add associated directory') self.photodb.log.debug('Committing - add associated directory')
@ -304,7 +304,7 @@ class Album(ObjectBase, GroupableMixin):
'albumid': self.id, 'albumid': self.id,
'photoid': photo.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() self._uncache_sums()
if commit: if commit:
@ -376,7 +376,7 @@ class Album(ObjectBase, GroupableMixin):
'title': self.title, 'title': self.title,
'description': self.description, '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: if commit:
self.photodb.log.debug('Committing - edit album') self.photodb.log.debug('Committing - edit album')
@ -525,7 +525,7 @@ class Bookmark(ObjectBase):
'title': self.title, 'title': self.title,
'url': self.url, '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: if commit:
self.photodb.log.debug('Committing - edit bookmark') self.photodb.log.debug('Committing - edit bookmark')
@ -623,12 +623,12 @@ class Photo(ObjectBase):
'photoid': self.id, 'photoid': self.id,
'tagid': tag.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 = { data = {
'id': self.id, 'id': self.id,
'tagged_at': helpers.now(), '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: if commit:
self.photodb.log.debug('Committing - add photo tag') self.photodb.log.debug('Committing - add photo tag')
@ -763,7 +763,7 @@ class Photo(ObjectBase):
'id': self.id, 'id': self.id,
'thumbnail': return_filepath, '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.thumbnail = return_filepath
self._uncache() self._uncache()
@ -900,7 +900,7 @@ class Photo(ObjectBase):
'duration': self.duration, 'duration': self.duration,
'bytes': self.bytes, '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() self._uncache()
if commit: if commit:
@ -937,7 +937,7 @@ class Photo(ObjectBase):
'id': self.id, 'id': self.id,
'filepath': new_filepath.absolute_path, '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() self._uncache()
if commit: if commit:
@ -963,7 +963,7 @@ class Photo(ObjectBase):
'id': self.id, 'id': self.id,
'tagged_at': helpers.now(), '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: if commit:
self.photodb.log.debug('Committing - remove photo tag') self.photodb.log.debug('Committing - remove photo tag')
@ -1103,7 +1103,7 @@ class Tag(ObjectBase, GroupableMixin):
'name': synname, 'name': synname,
'mastername': self.name, '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: if commit:
self.photodb.log.debug('Committing - add synonym') self.photodb.log.debug('Committing - add synonym')
@ -1149,7 +1149,7 @@ class Tag(ObjectBase, GroupableMixin):
'photoid': photoid, 'photoid': photoid,
'tagid': mastertag.id, '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 # Then delete the relationships with the old tag
self.delete() self.delete()
@ -1190,7 +1190,7 @@ class Tag(ObjectBase, GroupableMixin):
'id': self.id, 'id': self.id,
'description': self.description '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() self._uncache()
if commit: if commit:
@ -1299,7 +1299,7 @@ class Tag(ObjectBase, GroupableMixin):
'id': self.id, 'id': self.id,
'name': new_name, '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() cur = self.photodb.sql.cursor()
if apply_to_synonyms: if apply_to_synonyms:

View file

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