Replace manual DELETEs with calls to sql_delete.
This commit is contained in:
parent
a2e13003e8
commit
e4e542a8a6
1 changed files with 18 additions and 39 deletions
|
@ -109,7 +109,6 @@ class GroupableMixin:
|
||||||
Otherwise they'll just be raised up one level.
|
Otherwise they'll just be raised up one level.
|
||||||
'''
|
'''
|
||||||
self.photodb._cached_frozen_children = None
|
self.photodb._cached_frozen_children = None
|
||||||
cur = self.photodb.sql.cursor()
|
|
||||||
if delete_children:
|
if delete_children:
|
||||||
for child in self.get_children():
|
for child in self.get_children():
|
||||||
child.delete(delete_children=delete_children, commit=False)
|
child.delete(delete_children=delete_children, commit=False)
|
||||||
|
@ -119,10 +118,7 @@ class GroupableMixin:
|
||||||
if parent is None:
|
if parent is None:
|
||||||
# Since this group was a root, children become roots by removing
|
# Since this group was a root, children become roots by removing
|
||||||
# the row.
|
# the row.
|
||||||
cur.execute(
|
self.photodb.sql_delete(table=self.group_table, pairs={'parentid': self.id})
|
||||||
'DELETE FROM %s WHERE parentid == ?' % self.group_table,
|
|
||||||
[self.id]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Since this group was a child, its parent adopts all its children.
|
# Since this group was a child, its parent adopts all its children.
|
||||||
data = {
|
data = {
|
||||||
|
@ -132,10 +128,7 @@ class GroupableMixin:
|
||||||
|
|
||||||
# Note that this part comes after the deletion of children to prevent
|
# Note that this part comes after the deletion of children to prevent
|
||||||
# issues of recursion.
|
# issues of recursion.
|
||||||
cur.execute(
|
self.photodb.sql_delete(table=self.group_table, pairs={'memberid': self.id})
|
||||||
'DELETE FROM %s WHERE memberid == ?' % self.group_table,
|
|
||||||
[self.id]
|
|
||||||
)
|
|
||||||
self._uncache()
|
self._uncache()
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - delete tag')
|
self.photodb.log.debug('Committing - delete tag')
|
||||||
|
@ -193,12 +186,8 @@ class GroupableMixin:
|
||||||
'''
|
'''
|
||||||
Leave the current group and become independent.
|
Leave the current group and become independent.
|
||||||
'''
|
'''
|
||||||
cur = self.photodb.sql.cursor()
|
|
||||||
self.photodb._cached_frozen_children = None
|
self.photodb._cached_frozen_children = None
|
||||||
cur.execute(
|
self.photodb.sql_delete(table=self.group_table, pairs={'memberid': self.id})
|
||||||
'DELETE FROM %s WHERE memberid == ?' % self.group_table,
|
|
||||||
[self.id]
|
|
||||||
)
|
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - leave group')
|
self.photodb.log.debug('Committing - leave group')
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
@ -341,10 +330,9 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
def delete(self, *, delete_children=False, commit=True):
|
def delete(self, *, delete_children=False, commit=True):
|
||||||
self.photodb.log.debug('Deleting album {album:r}'.format(album=self))
|
self.photodb.log.debug('Deleting album {album:r}'.format(album=self))
|
||||||
GroupableMixin.delete(self, delete_children=delete_children, commit=False)
|
GroupableMixin.delete(self, delete_children=delete_children, commit=False)
|
||||||
cur = self.photodb.sql.cursor()
|
self.photodb.sql_delete(table='albums', pairs={'id': self.id})
|
||||||
cur.execute('DELETE FROM albums WHERE id == ?', [self.id])
|
self.photodb.sql_delete(table='album_photo_rel', pairs={'albumid': self.id})
|
||||||
cur.execute('DELETE FROM album_photo_rel WHERE albumid == ?', [self.id])
|
self.photodb.sql_delete(table='album_associated_directories', pairs={'albumid': self.id})
|
||||||
cur.execute('DELETE FROM album_associated_directories WHERE albumid == ?', [self.id])
|
|
||||||
self._uncache()
|
self._uncache()
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - delete album')
|
self.photodb.log.debug('Committing - delete album')
|
||||||
|
@ -434,11 +422,8 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.photodb.log.debug('Removing photo %s from %s', photo, self)
|
self.photodb.log.debug('Removing photo %s from %s', photo, self)
|
||||||
cur = self.photodb.sql.cursor()
|
pairs = {'albumid': self.id, 'photoid': photo.id}
|
||||||
cur.execute(
|
self.photodb.sql_delete(table='album_photo_rel', pairs=pairs)
|
||||||
'DELETE FROM album_photo_rel WHERE albumid == ? AND photoid == ?',
|
|
||||||
[self.id, photo.id]
|
|
||||||
)
|
|
||||||
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')
|
||||||
|
@ -499,8 +484,7 @@ class Bookmark(ObjectBase):
|
||||||
@decorators.required_feature('bookmark.edit')
|
@decorators.required_feature('bookmark.edit')
|
||||||
@decorators.transaction
|
@decorators.transaction
|
||||||
def delete(self, *, commit=True):
|
def delete(self, *, commit=True):
|
||||||
cur = self.photodb.sql.cursor()
|
self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id})
|
||||||
cur.execute('DELETE FROM bookmarks WHERE id == ?', [self.id])
|
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
||||||
|
@ -657,10 +641,9 @@ class Photo(ObjectBase):
|
||||||
Delete the Photo and its relation to any tags and albums.
|
Delete the Photo and its relation to any tags and albums.
|
||||||
'''
|
'''
|
||||||
self.photodb.log.debug('Deleting photo {photo:r}'.format(photo=self))
|
self.photodb.log.debug('Deleting photo {photo:r}'.format(photo=self))
|
||||||
cur = self.photodb.sql.cursor()
|
self.photodb.sql_delete(table='photos', pairs={'id': self.id})
|
||||||
cur.execute('DELETE FROM photos WHERE id == ?', [self.id])
|
self.photodb.sql_delete(table='photo_tag_rel', pairs={'photoid': self.id})
|
||||||
cur.execute('DELETE FROM photo_tag_rel WHERE photoid == ?', [self.id])
|
self.photodb.sql_delete(table='album_photo_rel', pairs={'photoid': self.id})
|
||||||
cur.execute('DELETE FROM album_photo_rel WHERE photoid == ?', [self.id])
|
|
||||||
|
|
||||||
if delete_file:
|
if delete_file:
|
||||||
path = self.real_path.absolute_path
|
path = self.real_path.absolute_path
|
||||||
|
@ -954,12 +937,9 @@ class Photo(ObjectBase):
|
||||||
self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self)))
|
self.photodb.log.debug('Removing tag {t} from photo {p}'.format(t=repr(tag), p=repr(self)))
|
||||||
tags = list(tag.walk_children())
|
tags = list(tag.walk_children())
|
||||||
|
|
||||||
cur = self.photodb.sql.cursor()
|
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
cur.execute(
|
pairs = {'photoid': self.id, 'tagid': tag.id}
|
||||||
'DELETE FROM photo_tag_rel WHERE photoid == ? AND tagid == ?',
|
self.photodb.sql_delete(table='photo_tag_rel', pairs=pairs)
|
||||||
[self.id, tag.id]
|
|
||||||
)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
|
@ -1188,10 +1168,9 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
self.photodb.log.debug('Deleting tag {tag:r}'.format(tag=self))
|
self.photodb.log.debug('Deleting tag {tag:r}'.format(tag=self))
|
||||||
self.photodb._cached_frozen_children = None
|
self.photodb._cached_frozen_children = None
|
||||||
GroupableMixin.delete(self, delete_children=delete_children, commit=False)
|
GroupableMixin.delete(self, delete_children=delete_children, commit=False)
|
||||||
cur = self.photodb.sql.cursor()
|
self.photodb.sql_delete(table='tags', pairs={'id': self.id})
|
||||||
cur.execute('DELETE FROM tags WHERE id == ?', [self.id])
|
self.photodb.sql_delete(table='photo_tag_rel', pairs={'tagid': self.id})
|
||||||
cur.execute('DELETE FROM photo_tag_rel WHERE tagid == ?', [self.id])
|
self.photodb.sql_delete(table='tag_synonyms', pairs={'mastername': self.name})
|
||||||
cur.execute('DELETE FROM tag_synonyms WHERE mastername == ?', [self.name])
|
|
||||||
self._uncache()
|
self._uncache()
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - delete tag')
|
self.photodb.log.debug('Committing - delete tag')
|
||||||
|
@ -1291,7 +1270,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
raise exceptions.NoSuchSynonym(synname)
|
raise exceptions.NoSuchSynonym(synname)
|
||||||
|
|
||||||
self.photodb._cached_frozen_children = None
|
self.photodb._cached_frozen_children = None
|
||||||
cur.execute('DELETE FROM tag_synonyms WHERE name == ?', [synname])
|
self.photodb.sql_delete(table='tag_synonyms', pairs={'name': synname})
|
||||||
if commit:
|
if commit:
|
||||||
self.photodb.log.debug('Committing - remove synonym')
|
self.photodb.log.debug('Committing - remove synonym')
|
||||||
self.photodb.commit()
|
self.photodb.commit()
|
||||||
|
|
Loading…
Reference in a new issue