[FIX] account_financial_report: Avoid slow vacuum due to ondelete=cascade

`report_journal_ledger` is auto-vacuumed as any transient model, but has some
ondelete="cascade" constraints that auto-remove subtables when a record is removed,
doing this operation very slow when selecting these sub-records.

Letting default ondelete="set null" would result in same performance bottleneck,
as the select on sub-table is performed the same for setting "null" value on them.

As a solution, and for avoiding a costly index operation, we delete by SQL sub-tables
rows in advance.

A bit of extra logic has been added for avoiding to remove that records if it's not
the turn of vacuum the parent table.
pull/868/head
Pedro M. Baeza 2019-08-17 20:25:18 +02:00 committed by Jasmin Solanki
parent ed07299e48
commit 88dbdff297
5 changed files with 27 additions and 1 deletions

View File

@ -111,6 +111,10 @@ Contributors
* Alexis de Lattre <alexis@via.ecp.fr>
* Mihai Fekete <feketemihai@gmail.com>
* Miquel Raïch <miquel.raich@eficent.com>
* `Tecnativa <https://www.tecnativa.com>`__:
* Pedro M. Baeza
* Sergio Teruel
Much of the work in this module was done at a sprint in Sorrento, Italy in
April 2016.

View File

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Account Financial Reports',
'version': '12.0.1.2.1',
'version': '12.0.1.2.2',
'category': 'Reporting',
'summary': 'OCA Financial Reports',
'author': 'Camptocamp SA,'

View File

@ -15,6 +15,10 @@
* Alexis de Lattre <alexis@via.ecp.fr>
* Mihai Fekete <feketemihai@gmail.com>
* Miquel Raïch <miquel.raich@eficent.com>
* `Tecnativa <https://www.tecnativa.com>`__:
* Pedro M. Baeza
* Sergio Teruel
Much of the work in this module was done at a sprint in Sorrento, Italy in
April 2016.

View File

@ -613,6 +613,19 @@ class ReportJournalLedger(models.TransientModel):
def get_html(self, given_context=None):
return self._get_html()
@api.model
def _transient_vacuum(self, force=False):
"""Remove journal ledger subtables first for avoiding a costly
ondelete operation.
"""
# Next 3 lines adapted from super method for mimicking behavior
cls = type(self)
if not force and (cls._transient_check_count < 21):
return True # no vacuum cleaning this time
self.env.cr.execute("DELETE FROM report_journal_ledger_move_line")
self.env.cr.execute("DELETE FROM report_journal_ledger_move")
return super(ReportJournalLedger, self)._transient_vacuum(force=force)
class ReportJournalLedgerJournal(models.TransientModel):

View File

@ -465,6 +465,11 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis&#64;via.ecp.fr">alexis&#64;via.ecp.fr</a>&gt;</li>
<li>Mihai Fekete &lt;<a class="reference external" href="mailto:feketemihai&#64;gmail.com">feketemihai&#64;gmail.com</a>&gt;</li>
<li>Miquel Raïch &lt;<a class="reference external" href="mailto:miquel.raich&#64;eficent.com">miquel.raich&#64;eficent.com</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>Sergio Teruel</li>
</ul>
</li>
</ul>
<p>Much of the work in this module was done at a sprint in Sorrento, Italy in
April 2016.</p>