From ba123c244fadcd177dec4de2a9ce53fb21e84139 Mon Sep 17 00:00:00 2001 From: Udo Spallek Date: Tue, 27 Dec 2011 14:12:23 +0100 Subject: [PATCH] Migrate invoice reports in chunks limited by cursor.IN_MAX issue2360 review207002 --- invoice.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/invoice.py b/invoice.py index 84bf3033cf..5bfff6dcdd 100644 --- a/invoice.py +++ b/invoice.py @@ -190,14 +190,22 @@ class Invoice(ModelWorkflow, ModelSQL, ModelView): if (table.column_exist('invoice_report') and table.column_exist('invoice_report_cache')): - cursor.execute('SELECT id, invoice_report ' + limit = cursor.IN_MAX + cursor.execute('SELECT COUNT(id) ' 'FROM "' + self._table + '"') - for invoice_id, report in cursor.fetchall(): - if report: - report = buffer(base64.decodestring(str(report))) - cursor.execute('UPDATE "' + self._table + '" ' - 'SET invoice_report_cache = %s ' - 'WHERE id = %s', (report, invoice_id)) + invoice_count, = cursor.fetchone() + for offset in range(0, invoice_count, limit): + cursor.execute(cursor.limit_clause( + 'SELECT id, invoice_report ' + 'FROM "' + self._table + '"' + 'ORDER BY id', + limit, offset)) + for invoice_id, report in cursor.fetchall(): + if report: + report = buffer(base64.decodestring(str(report))) + cursor.execute('UPDATE "' + self._table + '" ' + 'SET invoice_report_cache = %s ' + 'WHERE id = %s', (report, invoice_id)) table.drop_column('invoice_report') # Add index on create_date