forked from openlp/openlp
Only Vacuum changed databases
This commit is contained in:
parent
7dcd7f3011
commit
5d9ef61e2c
@ -117,6 +117,7 @@ class Manager(object):
|
|||||||
settings = QtCore.QSettings()
|
settings = QtCore.QSettings()
|
||||||
settings.beginGroup(plugin_name)
|
settings.beginGroup(plugin_name)
|
||||||
self.db_url = u''
|
self.db_url = u''
|
||||||
|
self.is_dirty = False
|
||||||
db_type = unicode(
|
db_type = unicode(
|
||||||
settings.value(u'db type', QtCore.QVariant(u'sqlite')).toString())
|
settings.value(u'db type', QtCore.QVariant(u'sqlite')).toString())
|
||||||
if db_type == u'sqlite':
|
if db_type == u'sqlite':
|
||||||
@ -150,6 +151,7 @@ class Manager(object):
|
|||||||
self.session.add(object_instance)
|
self.session.add(object_instance)
|
||||||
if commit:
|
if commit:
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
self.is_dirty = True
|
||||||
return True
|
return True
|
||||||
except InvalidRequestError:
|
except InvalidRequestError:
|
||||||
self.session.rollback()
|
self.session.rollback()
|
||||||
@ -220,6 +222,7 @@ class Manager(object):
|
|||||||
try:
|
try:
|
||||||
self.session.delete(object_instance)
|
self.session.delete(object_instance)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
self.is_dirty = True
|
||||||
return True
|
return True
|
||||||
except InvalidRequestError:
|
except InvalidRequestError:
|
||||||
self.session.rollback()
|
self.session.rollback()
|
||||||
@ -241,6 +244,7 @@ class Manager(object):
|
|||||||
query = query.filter(filter_clause)
|
query = query.filter(filter_clause)
|
||||||
query.delete(synchronize_session=False)
|
query.delete(synchronize_session=False)
|
||||||
self.session.commit()
|
self.session.commit()
|
||||||
|
self.is_dirty = True
|
||||||
return True
|
return True
|
||||||
except InvalidRequestError:
|
except InvalidRequestError:
|
||||||
self.session.rollback()
|
self.session.rollback()
|
||||||
@ -251,5 +255,6 @@ class Manager(object):
|
|||||||
"""
|
"""
|
||||||
VACUUM the database on exit.
|
VACUUM the database on exit.
|
||||||
"""
|
"""
|
||||||
engine = create_engine(self.db_url)
|
if self.is_dirty:
|
||||||
engine.execute("vacuum")
|
engine = create_engine(self.db_url)
|
||||||
|
engine.execute("vacuum")
|
||||||
|
Loading…
Reference in New Issue
Block a user