aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/db/sql/base.py6
-rw-r--r--mediagoblin/db/sql/util.py8
2 files changed, 8 insertions, 6 deletions
diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py
index 838080b0..e10e7739 100644
--- a/mediagoblin/db/sql/base.py
+++ b/mediagoblin/db/sql/base.py
@@ -79,11 +79,13 @@ 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)
- sess.commit()
+ if commit:
+ sess.commit()
Base = declarative_base(cls=GMGTableBase)
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):