Merge lp:~kangol/openobject-client-web/trunk-fix-templatelookup into lp:openobject-client-web/trunk

Proposed by Christophe Simonis (OpenERP)
Status: Merged
Merged at revision: 3801
Proposed branch: lp:~kangol/openobject-client-web/trunk-fix-templatelookup
Merge into: lp:openobject-client-web/trunk
Diff against target: 89 lines (+28/-22)
2 files modified
openobject/pooler.py (+7/-5)
openobject/tools/_expose.py (+21/-17)
To merge this branch: bzr merge lp:~kangol/openobject-client-web/trunk-fix-templatelookup
Reviewer Review Type Date Requested Status
OpenERP R&D Web Team Pending
Review via email: mp+39837@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Are you sure the template management stuff is going to work correctly when the pooler is restarted? It doesn't look cleaned up does it? Shouldn't we store our TemplateLookup instances in the pooler?

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Also I'm pretty sure this code used to use Mako's cache once upon a time, maybe check why this was replaced by a hand-rolled in-memory cache (and one working at a different level as well, doesn't mako cache the generated python code? Won't we have severe conflicts in case of multi-db situations?)

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

On 02 Nov 2010, at 13:11, Xavier (Open ERP) wrote:

> Are you sure the template management stuff is going to work correctly when the pooler is restarted?
Good catch.
> It doesn't look cleaned up does it?
I don't think so.
> Shouldn't we store our TemplateLookup instances in the pooler?
Not needed. Beside the fact that the login page doesn't have a pooler (but need a TemplateLookup), just poping the right key out of the cache when restarting the pooler is enough
> --
> https://code.launchpad.net/~kangol/openobject-client-web/trunk-fix-templatelookup/+merge/39837
> You are the owner of lp:~kangol/openobject-client-web/trunk-fix-templatelookup.

Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

On 02 Nov 2010, at 13:11, Xavier (Open ERP) wrote:

> Also I'm pretty sure this code used to use Mako's cache once upon a time, maybe check why this was replaced by a hand-rolled in-memory cache (and one working at a different level as well, doesn't mako cache the generated python code? Won't we have severe conflicts in case of multi-db situations?)
No problems about the mako cache.
> --
> https://code.launchpad.net/~kangol/openobject-client-web/trunk-fix-templatelookup/+merge/39837
> You are the owner of lp:~kangol/openobject-client-web/trunk-fix-templatelookup.

3775. By Christophe Simonis (OpenERP)

[FIX] remove db TemplateLookup from cache when restarting the pooler

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openobject/pooler.py'
2--- openobject/pooler.py 2010-10-21 10:32:40 +0000
3+++ openobject/pooler.py 2010-11-03 10:21:27 +0000
4@@ -63,15 +63,17 @@
5 def restart_pool():
6
7 db_name = cherrypy.session['db']
8-
9+
10 if db_name in pool_dict:
11 import addons
12-
13+ import tools._expose
14+
15 del pool_dict[db_name]
16 del addons._loaded[db_name]
17-
18+ tools._expose._template_lookups.pop(db_name, None)
19+
20 return get_pool()
21-
22+
23 def get_pool():
24
25 config = cherrypy.request.app.config
26@@ -88,7 +90,7 @@
27 import addons
28
29 pool = pool_dict[db_name] = Pool()
30-
31+
32 try:
33 addons.load_addons(db_name, config)
34 except:
35
36=== modified file 'openobject/tools/_expose.py'
37--- openobject/tools/_expose.py 2010-10-28 14:21:03 +0000
38+++ openobject/tools/_expose.py 2010-11-03 10:21:27 +0000
39@@ -52,22 +52,26 @@
40 filters = ["__content"]
41 imports = ["from openobject.tools import content as __content"]
42
43-class TL(TemplateLookup):
44-
45- cache = {}
46-
47- def get_template(self, uri):
48- try:
49- return self.cache[str(uri)]
50- except Exception, e:
51- pass
52- self.cache[str(uri)] = res = super(TL, self).get_template(uri)
53- return res
54-
55-template_lookup = TL(directories=[paths.root(), paths.addons()],
56- default_filters=filters,
57- imports=imports,
58- preprocessor=templating.edition_preprocessor)
59+_template_lookups = {} # XXX use mako.util.LRUCache ?
60+
61+def get_template_lookup():
62+ """Return the Template Lookup for the current database"""
63+ db_name = None
64+ try:
65+ db_name = cherrypy.session['db']
66+ except (AttributeError, KeyError):
67+ pass
68+
69+ try:
70+ return _template_lookups[db_name]
71+ except KeyError:
72+ lookup = _template_lookups[db_name] = TemplateLookup(
73+ directories=[paths.root(), paths.addons()],
74+ default_filters=filters,
75+ imports=imports,
76+ preprocessor=templating.edition_preprocessor)
77+ return lookup
78+
79
80 def load_template(template):
81
82@@ -75,7 +79,7 @@
83 return template
84
85 if re.match('(.+)\.(html|mako)\s*$', template):
86- return template_lookup.get_template(template)
87+ return get_template_lookup().get_template(template)
88 else:
89 return Template(template, default_filters=filters, imports=imports)
90