changeset ac039369474a in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=ac039369474a
description:
Use subquery to gain performance in account.account.party
issue10216
review353411002
diffstat:
account.py | 21 +++++++++++----------
move.py | 8 ++++++--
2 files changed, 17 insertions(+), 12 deletions(-)
diffs (59 lines):
diff -r 1ce785a9f7c3 -r ac039369474a account.py
--- a/account.py Sun Apr 11 20:51:49 2021 +0200
+++ b/account.py Mon Apr 12 20:48:57 2021 +0200
@@ -1321,25 +1321,26 @@
Account = pool.get('account.account')
line = Line.__table__()
account = Account.__table__()
+
+ account_party = line.select(
+ Min(line.id).as_('id'), line.account, line.party,
+ where=line.party != Null,
+ group_by=[line.account, line.party])
+
columns = []
- group_by = []
for fname, field in cls._fields.items():
if not hasattr(field, 'set'):
- if fname == 'id':
- column = Min(line.id)
- elif fname in {'account', 'party'}:
- column = Column(line, fname)
+ if fname in {'id', 'account', 'party'}:
+ column = Column(account_party, fname)
else:
column = Column(account, fname)
columns.append(column.as_(fname))
- if fname != 'id':
- group_by.append(column)
return (
- line.join(account, condition=line.account == account.id)
+ account_party.join(
+ account, condition=account_party.account == account.id)
.select(
*columns,
- where=(line.party != Null) & account.party_required,
- group_by=group_by))
+ where=account.party_required))
@classmethod
def get_balance(cls, records, name):
diff -r 1ce785a9f7c3 -r ac039369474a move.py
--- a/move.py Sun Apr 11 20:51:49 2021 +0200
+++ b/move.py Mon Apr 12 20:48:57 2021 +0200
@@ -768,9 +768,13 @@
def __register__(cls, module_name):
super(Line, cls).__register__(module_name)
- table = cls.__table_handler__(module_name)
+ table = cls.__table__()
+ table_h = cls.__table_handler__(module_name)
# Index for General Ledger
- table.index_action(['move', 'account'], 'add')
+ table_h.index_action(['move', 'account'], 'add')
+ # Index for account.account.party
+ table_h.index_action(
+ ['party', 'account', 'id'], 'add', where=table.party != Null)
@classmethod
def default_date(cls):