Browse Source

Cache the rules to avoid to many hits to the DB

As they are read on each partner write
pull/208/head
Guewen Baconnier 9 years ago
parent
commit
5cb3c4f637
  1. 21
      partner_revision/models/revision_behavior.py

21
partner_revision/models/revision_behavior.py

@ -20,6 +20,7 @@
#
from openerp import models, fields, api
from openerp.tools.cache import ormcache
class RevisionBehavior(models.Model):
@ -53,8 +54,26 @@ class RevisionBehavior(models.Model):
('never', 'Never'),
]
# TODO: cache
@ormcache()
@api.model
def get_rules(self, model_name):
rules = self.search([('model_id', '=', model_name)])
return {rule.field_id.name: rule for rule in rules}
@api.model
def create(self, vals):
record = super(RevisionBehavior, self).create(vals)
self.clear_caches()
return record
@api.multi
def write(self, vals):
result = super(RevisionBehavior, self).write(vals)
self.clear_caches()
return result
@api.multi
def unlink(self):
result = super(RevisionBehavior, self).unlink()
self.clear_caches()
return result
Loading…
Cancel
Save