-
Notifications
You must be signed in to change notification settings - Fork 21
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
bulk update of exchanges is slow with peewee #46
Comments
Original comment by Tomas Navarrete Gutierrez (Bitbucket: tomas_navarrete, ). like the private method |
Original comment by Tomas Navarrete Gutierrez (Bitbucket: tomas_navarrete, ). So, I found a quick hack to what I wanted to achieve, but I am not sure this is the right way to go. from brightway2 import *
from bw2data.backends.peewee import sqlite3_lci_db as db
import random
# ... project, db, activity finding
act = Database('my_db').get('myActivity')
with db.atomic() as txn:
for e in act.technosphere():
v = random.random()
e_ds = e._document
e_ds.data.update(amount = v)
e.save() Of course the raw import of the My doubt is specially on the need to recover the underlying document (ExchangeDataset) for the object (Exchange). It seems to work for now, but my request remains. ;) |
Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel). Yes, this is a weakness of the current model of abstraction layer cake. Actually, I think your approach is quite reasonable, though you could do something directly with The problem with |
Original report by Tomas Navarrete Gutierrez (Bitbucket: tomas_navarrete, ).
If I want to update all the amounts of the inputs of an activity (with different values), I would have to iterate over the technosphere of the activity, update the amount field per exchange, and call "save()" on each exchange. With n technosphere exchanges, this requires n transactions, in current implementation.
I would like to group the updates, so that there is only one transaction, and hopefully less I/O to hardrive.
The idea from: http://docs.peewee-orm.com/en/latest/peewee/querying.html#atomic-updates
something in the line of:
The text was updated successfully, but these errors were encountered: