Merge some small bits by spaetz. Needed later.
* commit '9437ea4742': Add commit argument to clean_orphan_tags Add "commit" argument to Base model delete()
This commit is contained in:
commit
efb70b529f
@ -79,10 +79,12 @@ class GMGTableBase(object):
|
||||
sess.add(self)
|
||||
sess.commit()
|
||||
|
||||
def delete(self):
|
||||
def delete(self, commit=True):
|
||||
"""Delete the object and commit the change immediately by default"""
|
||||
sess = object_session(self)
|
||||
assert sess is not None, "Not going to delete detached %r" % self
|
||||
sess.delete(self)
|
||||
if commit:
|
||||
sess.commit()
|
||||
|
||||
|
||||
|
@ -297,16 +297,16 @@ def media_entries_for_tag_slug(dummy_db, tag_slug):
|
||||
& (Tag.slug == tag_slug))
|
||||
|
||||
|
||||
def clean_orphan_tags():
|
||||
def clean_orphan_tags(commit=True):
|
||||
"""Search for unused MediaTags and delete them"""
|
||||
q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
|
||||
for t in q1:
|
||||
Session.delete(t)
|
||||
|
||||
# The "let the db do all the work" version:
|
||||
# q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None)
|
||||
# q2 = Session.query(Tag).filter(Tag.id.in_(q1))
|
||||
# q2.delete(synchronize_session = False)
|
||||
|
||||
if commit:
|
||||
Session.commit()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user