diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 7c4536ccf..e59a9737b 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -117,6 +117,7 @@ class Manager(object): settings = QtCore.QSettings() settings.beginGroup(plugin_name) self.db_url = u'' + self.is_dirty = False db_type = unicode( settings.value(u'db type', QtCore.QVariant(u'sqlite')).toString()) if db_type == u'sqlite': @@ -150,6 +151,7 @@ class Manager(object): self.session.add(object_instance) if commit: self.session.commit() + self.is_dirty = True return True except InvalidRequestError: self.session.rollback() @@ -220,6 +222,7 @@ class Manager(object): try: self.session.delete(object_instance) self.session.commit() + self.is_dirty = True return True except InvalidRequestError: self.session.rollback() @@ -241,6 +244,7 @@ class Manager(object): query = query.filter(filter_clause) query.delete(synchronize_session=False) self.session.commit() + self.is_dirty = True return True except InvalidRequestError: self.session.rollback() @@ -251,5 +255,6 @@ class Manager(object): """ VACUUM the database on exit. """ - engine = create_engine(self.db_url) - engine.execute("vacuum") + if self.is_dirty: + engine = create_engine(self.db_url) + engine.execute("vacuum")