Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] mail: cache all mail-related config parameters in one query
- Loading branch information
1 parent
cd69ea8
commit 6b37760
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import api, models | ||
from odoo.tools import ormcache | ||
|
||
|
||
class IrConfigParameter(models.Model): | ||
_name = 'ir.config_parameter' | ||
_inherit = 'ir.config_parameter' | ||
|
||
_KEYS = ('mail.catchall.alias', | ||
'mail.catchall.domain', | ||
'mail.bounce.alias', | ||
'mail.session.batch.size', | ||
'mail.batch_size', | ||
'web.base.url') | ||
|
||
@api.model | ||
def get_param(self, key, default=False): | ||
if key in self._KEYS: | ||
return self._get_mail_params().get(key, default) | ||
return super(IrConfigParameter, self).get_param(key, default=default) | ||
|
||
@ormcache('self.env.uid') | ||
def _get_mail_params(self): | ||
params = self.env['ir.config_parameter'].search_read([ | ||
('key', 'in', self._KEYS)], fields=['key', 'value']) | ||
return dict((param['key'], param['value']) for param in params) |