Skip to content

Commit

Permalink
[FIX] models: do less snapshots in onchange()
Browse files Browse the repository at this point in the history
Create a snapshot after having processed a batch of fields, then use it
to determine the next batch to process.

For instance, assume that field A modifies fields B and C, and that
field C modifies fields D, E and F:
 - before: 6 snapshots (process A, snapshot, process B, snapshot,
   process C, snapshot, process D, snapshot, process E, snapshot,
   process F, snapshot)
 - after: 3 snapshots (process A, snapshot, process B, process C,
   snapshot, process D, process E, process F, snapshot)
  • Loading branch information
rco-odoo committed Mar 15, 2019
1 parent 1c91276 commit 616e8bf
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions odoo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5182,24 +5182,22 @@ def diff(self, other):

result = {}

# process names in order (or the keys of values if no name given)
while todo:
name = todo.pop(0)
if name in done:
continue
done.add(name)

with env.do_in_onchange():
# process names in order
with env.do_in_onchange():
while todo:
# apply field-specific onchange methods
if field_onchange.get(name):
record._onchange_eval(name, field_onchange[name], result)
for name in todo:
if field_onchange.get(name):
record._onchange_eval(name, field_onchange[name], result)
done.add(name)

# make a snapshot (this forces evaluation of computed fields)
snapshot1 = Snapshot(record, nametree)

# determine which fields have been modified
# determine which fields to process for the next pass
todo.clear()
for name in nametree:
if snapshot1[name] != snapshot0[name]:
if name not in done and snapshot1[name] != snapshot0[name]:
todo.append(name)

# determine values that have changed by comparing snapshots
Expand Down

0 comments on commit 616e8bf

Please sign in to comment.