Merge lp:~therp-nl/openobject-addons/7.0-lp1078689-audittrail_bad_performance_and_infinit_recursion into lp:openobject-addons

Proposed by Stefan Rijnhart (Opener)
Status: Needs review
Proposed branch: lp:~therp-nl/openobject-addons/7.0-lp1078689-audittrail_bad_performance_and_infinit_recursion
Merge into: lp:openobject-addons
Diff against target: 80 lines (+12/-6)
1 file modified
audittrail/audittrail.py (+12/-6)
To merge this branch: bzr merge lp:~therp-nl/openobject-addons/7.0-lp1078689-audittrail_bad_performance_and_infinit_recursion
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+134290@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

8034. By Stefan Rijnhart (Opener)

[FIX] Audittrail: bad performance and infinite recursion

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'audittrail/audittrail.py'
2--- audittrail/audittrail.py 2012-11-12 08:40:18 +0000
3+++ audittrail/audittrail.py 2012-11-14 12:20:30 +0000
4@@ -174,6 +174,8 @@
5 class audittrail_objects_proxy(object_proxy):
6 """ Uses Object proxy for auditing changes on object of subscribed Rules"""
7
8+ _default_recursive_level = 1
9+
10 def get_value_text(self, cr, uid, pool, resource_pool, method, field, value):
11 """
12 Gets textual values for the fields.
13@@ -303,7 +305,7 @@
14 self.process_data(cr, uid_orig, pool, res_ids, model, method, old_values, new_values, field_list)
15 return res
16
17- def get_data(self, cr, uid, pool, res_ids, model, method):
18+ def get_data(self, cr, uid, pool, res_ids, model, method, recursive_level=None):
19 """
20 This function simply read all the fields of the given res_ids, and also recurisvely on
21 all records of a x2m fields read that need to be logged. Then it returns the result in
22@@ -322,6 +324,8 @@
23 },
24 }
25 """
26+ if recursive_level is None:
27+ recursive_level = self._default_recursive_level
28 data = {}
29 resource_pool = pool.get(model.model)
30 # read all the fields of the given resources in super admin mode
31@@ -338,7 +342,7 @@
32 values_text[field] = self.get_value_text(cr, SUPERUSER_ID, pool, resource_pool, method, field, resource[field])
33
34 field_obj = resource_pool._all_columns.get(field).column
35- if field_obj._type in ('one2many','many2many'):
36+ if field_obj._type in ('one2many','many2many') and recursive_level:
37 # check if an audittrail rule apply in super admin mode
38 if self.check_rules(cr, SUPERUSER_ID, field_obj._obj, method):
39 # check if the model associated to a *2m field exists, in super admin mode
40@@ -347,11 +351,11 @@
41 assert x2m_model_id, _("'%s' Model does not exist..." %(field_obj._obj))
42 x2m_model = pool.get('ir.model').browse(cr, SUPERUSER_ID, x2m_model_id)
43 #recursive call on x2m fields that need to be checked too
44- data.update(self.get_data(cr, SUPERUSER_ID, pool, resource[field], x2m_model, method))
45+ data.update(self.get_data(cr, SUPERUSER_ID, pool, resource[field], x2m_model, method, recursive_level - 1))
46 data[(model.id, resource_id)] = {'text':values_text, 'value': values}
47 return data
48
49- def prepare_audittrail_log_line(self, cr, uid, pool, model, resource_id, method, old_values, new_values, field_list=None):
50+ def prepare_audittrail_log_line(self, cr, uid, pool, model, resource_id, method, old_values, new_values, field_list=None, recursive_level=None):
51 """
52 This function compares the old data (i.e before the method was executed) and the new data
53 (after the method was executed) and returns a structure with all the needed information to
54@@ -380,6 +384,8 @@
55 The reason why the structure returned is build as above is because when modifying an existing
56 record, we may have to log a change done in a x2many field of that object
57 """
58+ if recursive_level is None:
59+ recursive_level = self._default_recursive_level
60 if field_list is None:
61 field_list = []
62 key = (model.id, resource_id)
63@@ -394,7 +400,7 @@
64 if field_list and field_name not in field_list:
65 continue
66 field_obj = field_definition.column
67- if field_obj._type in ('one2many','many2many'):
68+ if field_obj._type in ('one2many','many2many') and recursive_level:
69 # checking if an audittrail rule apply in super admin mode
70 if self.check_rules(cr, SUPERUSER_ID, field_obj._obj, method):
71 # checking if the model associated to a *2m field exists, in super admin mode
72@@ -409,7 +415,7 @@
73 # We use list(set(...)) to remove duplicates.
74 res_ids = list(set(x2m_old_values_ids + x2m_new_values_ids))
75 for res_id in res_ids:
76- lines.update(self.prepare_audittrail_log_line(cr, SUPERUSER_ID, pool, x2m_model, res_id, method, old_values, new_values, field_list))
77+ lines.update(self.prepare_audittrail_log_line(cr, SUPERUSER_ID, pool, x2m_model, res_id, method, old_values, new_values, field_list, recursive_level=recursive_level - 1))
78 # if the value value is different than the old value: record the change
79 if key not in old_values or key not in new_values or old_values[key]['value'][field_name] != new_values[key]['value'][field_name]:
80 data = {

Subscribers

People subscribed via source and target branches

to all changes: