From 0e93d14bacf710b163221bbb7ad612328eeb52f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 13 Apr 2013 13:39:56 +0200 Subject: [PATCH] cache vocabulary --- src/collective/dms/thesaurus/vocabulary.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/collective/dms/thesaurus/vocabulary.py b/src/collective/dms/thesaurus/vocabulary.py index f0637cc..0c950b4 100644 --- a/src/collective/dms/thesaurus/vocabulary.py +++ b/src/collective/dms/thesaurus/vocabulary.py @@ -26,7 +26,11 @@ class ThesaurusVocabulary(SimpleVocabulary): class InternalThesaurusSource(object): implements(IContextSourceBinder) + _vocabulary = None + def __call__(self, context): + if self._vocabulary is not None: + return self._vocabulary catalog = getToolByName(context, 'portal_catalog') path = '/'.join(context.getPhysicalPath()) results = catalog(portal_type='dmskeyword', @@ -38,7 +42,7 @@ class InternalThesaurusSource(object): #keyword_ids = [x.id for x in keywords] _c = SimpleVocabulary.createTerm keyword_terms = [ _c(x.id, x.id, x.title) for x in keywords ] - return ThesaurusVocabulary(keyword_terms) + self._vocabulary = ThesaurusVocabulary(keyword_terms) def __iter__(self): # hack to let schema editor handle the field