Only vacuum db if anything was written.
This commit is contained in:
parent
821e3f713c
commit
5ba5ceef49
7
MosDb.py
7
MosDb.py
@ -9,12 +9,14 @@ class MosDb():
|
||||
self.conn = sqlite3.connect(self.dbfile)
|
||||
self.c = self.conn.cursor()
|
||||
self.c.execute("PRAGMA foreign_keys=on;")
|
||||
self.changes_made = False
|
||||
|
||||
def commit(self):
|
||||
self.conn.commit()
|
||||
|
||||
def finish(self):
|
||||
self.c.execute("VACUUM")
|
||||
if self.changes_made:
|
||||
self.c.execute("VACUUM")
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
@ -29,6 +31,7 @@ class MosDb():
|
||||
def add_new_id(self, table, col, value):
|
||||
self.c.execute("INSERT INTO " + table + " (" + col + ") VALUES (?)", (value,))
|
||||
self.conn.commit()
|
||||
self.changes_made = True
|
||||
rid = self.c.lastrowid
|
||||
self.idcache[table][value] = rid
|
||||
self.ridcache[table][rid] = value
|
||||
@ -87,6 +90,7 @@ class MosDb():
|
||||
"INSERT OR REPLACE INTO " + table + " (" + fieldsList + ") VALUES (" + placeHolders + ")",
|
||||
valuesTuple
|
||||
)
|
||||
self.changes_made = True
|
||||
|
||||
def mark_deleted(self, objData):
|
||||
"""Sets the isDeleted column to 1 for the specified object.
|
||||
@ -98,6 +102,7 @@ class MosDb():
|
||||
"UPDATE mosobjects SET isDeleted=1 WHERE mosId=? AND objId=?",
|
||||
( self.get_mos_id(objData["mosId"]), objData["objId"] )
|
||||
)
|
||||
self.changes_made = True
|
||||
|
||||
def add_or_replace(self, objData):
|
||||
insertObj = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user