Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #128 to fix #127 on bw2legacy #130

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bw2data/backends/peewee/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down