Merge lp:~openerp-dev/openobject-server/7.0-transient-al into lp:openobject-server/7.0

Proposed by Antony Lesuisse (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-transient-al
Merge into: lp:openobject-server/7.0
Diff against target: 96 lines (+5/-42)
2 files modified
openerp/osv/orm.py (+4/-37)
openerp/tools/config.py (+1/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-transient-al
Reviewer Review Type Date Requested Status
Antony Lesuisse (OpenERP) Needs Fixing
Review via email: mp+141455@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Antony Lesuisse (OpenERP) (al-openerp) wrote :

It doesnt work if any wizard fail to unlink like the multi account chart wizard

review: Needs Fixing

Unmerged revisions

4760. By Antony Lesuisse (OpenERP)

TransientModel deprecate count based vaccum, remove create hooks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2012-12-27 17:28:25 +0000
3+++ openerp/osv/orm.py 2012-12-29 14:55:24 +0000
4@@ -1069,8 +1069,6 @@
5
6 # Transience
7 if self.is_transient():
8- self._transient_check_count = 0
9- self._transient_max_count = config.get('osv_memory_count_limit')
10 self._transient_max_hours = config.get('osv_memory_age_limit')
11 assert self._log_access, "TransientModels must have log_access turned on, "\
12 "in order to implement their access rights policy"
13@@ -4305,9 +4303,6 @@
14 if not context:
15 context = {}
16
17- if self.is_transient():
18- self._transient_vacuum(cr, user)
19-
20 self.check_access_rights(cr, user, 'create')
21
22 if self._log_access:
23@@ -5154,46 +5149,18 @@
24 ids = [x[0] for x in cr.fetchall()]
25 self.unlink(cr, SUPERUSER_ID, ids)
26
27- def _transient_clean_old_rows(self, cr, max_count):
28- # Check how many rows we have in the table
29- cr.execute("SELECT count(*) AS row_count FROM " + self._table)
30- res = cr.fetchall()
31- if res[0][0] <= max_count:
32- return # max not reached, nothing to do
33- self._transient_clean_rows_older_than(cr, 300)
34-
35 def _transient_vacuum(self, cr, uid, force=False):
36- """Clean the transient records.
37+ """Clean the TransientModel records.
38
39- This unlinks old records from the transient model tables whenever the
40- "_transient_max_count" or "_max_age" conditions (if any) are reached.
41- Actual cleaning will happen only once every "_transient_check_time" calls.
42- This means this method can be called frequently called (e.g. whenever
43- a new record is created).
44- Example with both max_hours and max_count active:
45- Suppose max_hours = 0.2 (e.g. 12 minutes), max_count = 20, there are 55 rows in the
46- table, 10 created/changed in the last 5 minutes, an additional 12 created/changed between
47- 5 and 10 minutes ago, the rest created/changed more then 12 minutes ago.
48- - age based vacuum will leave the 22 rows created/changed in the last 12 minutes
49- - count based vacuum will wipe out another 12 rows. Not just 2, otherwise each addition
50- would immediately cause the maximum to be reached again.
51- - the 10 rows that have been created/changed the last 5 minutes will NOT be deleted
52+ This unlinks transient if the "_max_age" is reached. A cron job is
53+ defined on osv_memory.autovacuum that calls _transient_vacuum on every
54+ transient model.
55 """
56 assert self._transient, "Model %s is not transient, it cannot be vacuumed!" % self._name
57- _transient_check_time = 20 # arbitrary limit on vacuum executions
58- self._transient_check_count += 1
59- if not force and (self._transient_check_count < _transient_check_time):
60- return True # no vacuum cleaning this time
61- self._transient_check_count = 0
62-
63 # Age-based expiration
64 if self._transient_max_hours:
65 self._transient_clean_rows_older_than(cr, self._transient_max_hours * 60 * 60)
66
67- # Count-based expiration
68- if self._transient_max_count:
69- self._transient_clean_old_rows(cr, self._transient_max_count)
70-
71 return True
72
73 def resolve_2many_commands(self, cr, uid, field_name, commands, fields=None, context=None):
74
75=== modified file 'openerp/tools/config.py'
76--- openerp/tools/config.py 2012-12-29 13:22:16 +0000
77+++ openerp/tools/config.py 2012-12-29 14:55:24 +0000
78@@ -261,10 +261,6 @@
79 help="stop the server after its initialization")
80 group.add_option("-t", "--timezone", dest="timezone", my_default=False,
81 help="specify reference timezone for the server (e.g. Europe/Brussels")
82- group.add_option("--osv-memory-count-limit", dest="osv_memory_count_limit", my_default=False,
83- help="Force a limit on the maximum number of records kept in the virtual "
84- "osv_memory tables. The default is False, which means no count-based limit.",
85- type="int")
86 group.add_option("--osv-memory-age-limit", dest="osv_memory_age_limit", my_default=1.0,
87 help="Force a limit on the maximum age of records kept in the virtual "
88 "osv_memory tables. This is a decimal value expressed in hours, "
89@@ -407,7 +403,7 @@
90 'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
91 'list_db', 'xmlrpcs', 'proxy_mode',
92 'test_file', 'test_enable', 'test_commit', 'test_report_directory',
93- 'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
94+ 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
95 'workers', 'limit_memory_hard', 'limit_memory_soft', 'limit_time_cpu', 'limit_time_real', 'limit_request'
96 ]
97