diff --git a/bw2data/backends/peewee/database.py b/bw2data/backends/peewee/database.py index 3fc85482..80909be6 100644 --- a/bw2data/backends/peewee/database.py +++ b/bw2data/backends/peewee/database.py @@ -214,6 +214,10 @@ def _efficient_write_many_data(self, data, indices=True): if exchanges: ExchangeDataset.insert_many(exchanges).execute() sqlite3_lci_db.db.commit() + if len(self) > 500: + sqlite3_lci_db.vacuum() + + except: sqlite3_lci_db.db.rollback() raise @@ -327,8 +331,6 @@ def delete(self, keep_params=False, warn=True): """ warnings.warn(MESSAGE.format(self.name), UserWarning) - vacuum_needed = len(self) > 500 - ActivityDataset.delete().where(ActivityDataset.database== self.name).execute() ExchangeDataset.delete().where(ExchangeDataset.output_database== self.name).execute() IndexManager(self.filename).delete_database() @@ -345,9 +347,6 @@ def delete(self, keep_params=False, warn=True): ActivityParameter.delete().where(ActivityParameter.database == self.name).execute() DatabaseParameter.delete().where(DatabaseParameter.database == self.name).execute() - if vacuum_needed: - sqlite3_lci_db.vacuum() - def process(self): """ Process inventory documents to NumPy structured arrays.