From d6acdf8470f4cbb569ff0d64294623bf4dc9723b 2017-07-26 15:32:58 From: Lance Edgar Date: 2017-07-26 15:32:58 Subject: [PATCH] Avoid session auto-flush when populating or refreshing a batch this is primarily needed when continuum versioning is enabled, to make sure things don't slow way down due to session flush hook --- diff --git a/rattail/batch/handlers.py b/rattail/batch/handlers.py index ecaa2585a101e67cefa53db0cf5d601fef65040c..220f1cf25fba1abe7da94beab81cdd2bfbc06a07 100644 --- a/rattail/batch/handlers.py +++ b/rattail/batch/handlers.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework @@ -99,7 +99,7 @@ class BatchHandler(object): session = orm.object_session(batch) with session.no_autoflush: batch.data_rows.append(row) - self.refresh_row(row) + self.refresh_row(row) if not row.removed: batch.rowcount += 1 @@ -230,11 +230,13 @@ class BatchHandler(object): such data will be left intact, with all *other* data values being re-calculated and/or reset etc. """ + session = orm.object_session(batch) self.setup_refresh(batch, progress=progress) batch.rowcount = 0 def refresh(row, i): - self.refresh_row(row) + with session.no_autoflush: + self.refresh_row(row) if not row.removed: batch.rowcount += 1 diff --git a/rattail/batch/vendorinvoice.py b/rattail/batch/vendorinvoice.py index 283155b3a5533906ff14c0959a85d27cad5335e7..d0ff4a932236ef3edc6d7af5ec9d5ac459045276 100644 --- a/rattail/batch/vendorinvoice.py +++ b/rattail/batch/vendorinvoice.py @@ -75,8 +75,7 @@ class VendorInvoiceHandler(BatchHandler): self.setup_populate(batch, progress=progress) def append(row, i): - batch.add_row(row) - self.refresh_row(row) + self.add_row(batch, row) if i % 250 == 0: session.flush()