diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-11-28 14:36:58 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2012-11-28 14:43:04 +0100 |
commit | 9437ea4742eecb6854810fe020fe721b413da276 (patch) | |
tree | 561a44c6e1c1ad62bfb0be67a040d718268c198c /mediagoblin/db/sql/util.py | |
parent | 329e39034b2ef2a9663fc2de16c8eae6c0313fdc (diff) | |
download | mediagoblin-9437ea4742eecb6854810fe020fe721b413da276.tar.lz mediagoblin-9437ea4742eecb6854810fe020fe721b413da276.tar.xz mediagoblin-9437ea4742eecb6854810fe020fe721b413da276.zip |
Add commit argument to clean_orphan_tags
So we can prevent the session from being committed if we don't want it.
Diffstat (limited to 'mediagoblin/db/sql/util.py')
-rw-r--r-- | mediagoblin/db/sql/util.py | 8 |
1 files changed, 4 insertions, 4 deletions
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): |