Skip to content
Snippets Groups Projects
Commit 7a56040a authored by Fabien Meghazi's avatar Fabien Meghazi
Browse files

[ADD] cache for get_current_website() (remove one query per request)

parent 1900c912
No related branches found
No related tags found
No related merge requests found
...@@ -251,11 +251,19 @@ class website(osv.osv): ...@@ -251,11 +251,19 @@ class website(osv.osv):
lang['hreflang'] = lang['short'] lang['hreflang'] = lang['short']
return langs return langs
@openerp.tools.ormcache(skiparg=4)
def _get_current_website_id(self, cr, uid, context=None):
website_id = 1
if request:
domain_name = request.httprequest.environ.get('HTTP_HOST', '').split(':')[0]
ids = self.search(cr, uid, [('name', '=', domain_name)], context=context)
if ids:
website_id = ids[0]
return website_id
def get_current_website(self, cr, uid, context=None): def get_current_website(self, cr, uid, context=None):
domain_name=request.httprequest.host.split(":")[0].lower() website_id = self._get_current_website_id(cr, uid, context=context)
ids=self.search(cr, uid, [('name', '=', domain_name)], context=context) return self.browse(cr, uid, website_id, context=context)
website = self.browse(cr, uid, ids and ids[0] or 1, context=context)
return website
def is_publisher(self, cr, uid, ids, context=None): def is_publisher(self, cr, uid, ids, context=None):
Access = self.pool['ir.model.access'] Access = self.pool['ir.model.access']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment