From: Sebastian Spaeth Date: Wed, 28 Nov 2012 13:36:58 +0000 (+0100) Subject: Add commit argument to clean_orphan_tags X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9437ea4742eecb6854810fe020fe721b413da276;p=mediagoblin.git Add commit argument to clean_orphan_tags So we can prevent the session from being committed if we don't want it. --- diff --git a/mediagoblin/db/sql/util.py b/mediagoblin/db/sql/util.py index bd92393c..c6d8562e 100644 --- a/mediagoblin/db/sql/util.py +++ b/mediagoblin/db/sql/util.py @@ -297,17 +297,17 @@ 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) - - Session.commit() + if commit: + Session.commit() def check_collection_slug_used(dummy_db, creator_id, slug, ignore_c_id):