Changeset - d6acdf8470f4
[Not reviewed]
0 2 0
Lance Edgar (lance) - 7 years ago 2017-07-26 15:32:58
lance@edbob.org
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
2 files changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rattail/batch/handlers.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
@@ -96,13 +96,13 @@ class BatchHandler(object):
 
        (Try to) Add the given row to the given batch.  This assumes it is a
 
        *new* row, perhaps along with other assumptions?
 
        """
 
        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
 

	
 
    @property
 
    def root_datadir(self):
 
        """
 
@@ -227,17 +227,19 @@ class BatchHandler(object):
 
        Generally speaking this refresh is meant to use queries etc. to obtain
 
        "fresh" data for the batch (header) and all its rows.  In most cases
 
        certain data is expected to be "core" to the batch and/or rows, and
 
        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
 

	
 
        success = self.progress_loop(refresh, batch.active_rows(), progress,
 
                                     message="Refreshing batch data rows")
 
        self.refresh_batch_status(batch)
rattail/batch/vendorinvoice.py
Show inline comments
 
@@ -72,14 +72,13 @@ class VendorInvoiceHandler(BatchHandler):
 
        parser.vendor = api.get_vendor(session, parser.vendor_key)
 
        assert batch.vendor is parser.vendor
 
        batch.invoice_date = parser.parse_invoice_date(path)
 
        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()
 

	
 
        data = list(parser.parse_rows(path))
 
        assert self.progress_loop(append, data, progress,
 
                                  message="Adding initial rows to batch")
0 comments (0 inline, 0 general)