Commit c46302e0 authored by Jérome Perrin's avatar Jérome Perrin

use a threading.local for SEARCH_KEY_INSTANCE_POOL



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20640 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 53d4eaab
...@@ -39,6 +39,7 @@ import sys ...@@ -39,6 +39,7 @@ import sys
import urllib import urllib
import string import string
import pprint import pprint
import threading
from cStringIO import StringIO from cStringIO import StringIO
from xml.dom.minidom import parse from xml.dom.minidom import parse
from xml.sax.saxutils import escape, quoteattr from xml.sax.saxutils import escape, quoteattr
...@@ -2371,13 +2372,23 @@ Globals.default__class_init__(Catalog) ...@@ -2371,13 +2372,23 @@ Globals.default__class_init__(Catalog)
class CatalogError(Exception): pass class CatalogError(Exception): pass
# pool of global preinitialized search keys instances
SEARCH_KEY_INSTANCE_POOL = threading.local()
# hook search keys and Query implementation # hook search keys and Query implementation
def getSearchKeyInstance(search_key_class): def getSearchKeyInstance(search_key_class):
""" Return instance of respective search_key class. """ Return instance of respective search_key class.
We should have them initialized only once.""" We should have them initialized only once."""
global SEARCH_KEY_INSTANCE_POOL global SEARCH_KEY_INSTANCE_POOL
lexer = SEARCH_KEY_INSTANCE_POOL[search_key_class] if not hasattr(SEARCH_KEY_INSTANCE_POOL, 'pool'):
return lexer pool = dict()
for klass in (DefaultKey, RawKey, KeyWordKey, DateTimeKey,
FullTextKey, FloatKey, ScriptableKey, KeyMappingKey):
search_key_instance = klass()
search_key_instance.build()
pool[klass] = search_key_instance
SEARCH_KEY_INSTANCE_POOL.pool = pool
return SEARCH_KEY_INSTANCE_POOL.pool[search_key_class]
from Query.Query import QueryMixin from Query.Query import QueryMixin
from Query.SimpleQuery import NegatedQuery, SimpleQuery from Query.SimpleQuery import NegatedQuery, SimpleQuery
...@@ -2386,7 +2397,7 @@ from Query.ComplexQuery import ComplexQuery ...@@ -2386,7 +2397,7 @@ from Query.ComplexQuery import ComplexQuery
# for of backwards compatability # for of backwards compatability
QueryMixin = QueryMixin QueryMixin = QueryMixin
Query = SimpleQuery Query = SimpleQuery
NegatedQuery = NegatedQuery NegatedQuery = NegatedQuery
ComplexQuery = ComplexQuery ComplexQuery = ComplexQuery
from Products.ZSQLCatalog.SearchKey.DefaultKey import DefaultKey from Products.ZSQLCatalog.SearchKey.DefaultKey import DefaultKey
...@@ -2397,10 +2408,4 @@ from Products.ZSQLCatalog.SearchKey.FullTextKey import FullTextKey ...@@ -2397,10 +2408,4 @@ from Products.ZSQLCatalog.SearchKey.FullTextKey import FullTextKey
from Products.ZSQLCatalog.SearchKey.FloatKey import FloatKey from Products.ZSQLCatalog.SearchKey.FloatKey import FloatKey
from Products.ZSQLCatalog.SearchKey.ScriptableKey import ScriptableKey, KeyMappingKey from Products.ZSQLCatalog.SearchKey.ScriptableKey import ScriptableKey, KeyMappingKey
# pool of global preinitialized search keys instances
SEARCH_KEY_INSTANCE_POOL = {}
for search_key_class in (DefaultKey, RawKey, KeyWordKey, DateTimeKey,
FullTextKey, FloatKey, ScriptableKey, KeyMappingKey):
search_key_instance = search_key_class()
search_key_instance.build()
SEARCH_KEY_INSTANCE_POOL[search_key_class] = search_key_instance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment