projects
/
Plinn.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b48c89e
)
Réutilisation de la connexion Solr, pour ne pas en ouvrir plus que nécessaire.
author
Benoît Pin
<pin@cri.ensmp.fr>
Tue, 8 Jul 2014 12:45:29 +0000
(14:45 +0200)
committer
Benoît Pin
<pin@cri.ensmp.fr>
Tue, 8 Jul 2014 12:45:29 +0000
(14:45 +0200)
catalog.py
patch
|
blob
|
history
diff --git
a/catalog.py
b/catalog.py
index
4b925bf
..
05cbd59
100644
(file)
--- a/
catalog.py
+++ b/
catalog.py
@@
-18,17
+18,21
@@
from BTrees.IIBTree import intersection, IISet
from BTrees.IIBTree import weightedIntersection
import warnings
from BTrees.IIBTree import weightedIntersection
import warnings
+_VOLATILE_SOLR_NAME = '_v_solrConnection'
+
class SolrTransactionHook :
''' commit solr couplé sur le commit de la ZODB '''
class SolrTransactionHook :
''' commit solr couplé sur le commit de la ZODB '''
- def __init__(self, con
nection
) :
- self.con
nection = connection
+ def __init__(self, con
text
) :
+ self.con
text = context
def __call__(self, status) :
def __call__(self, status) :
+ con = getattr(self.context, _VOLATILE_SOLR_NAME)
if status :
if status :
-
self.connecti
on.commit()
-
self.connecti
on.close()
+
c
on.commit()
+
c
on.close()
else :
else :
- self.connection.close()
+ con.close()
+ delattr(self.context, _VOLATILE_SOLR_NAME)
class CatalogTool(BaseCatalogTool) :
meta_type = 'Plinn Catalog'
class CatalogTool(BaseCatalogTool) :
meta_type = 'Plinn Catalog'
@@
-45,6
+49,14
@@
class CatalogTool(BaseCatalogTool) :
self.solr_url = 'http://localhost:8983/solr'
self.delegatedIndexes = ('Title', 'Description', 'SearchableText')
self.solr_url = 'http://localhost:8983/solr'
self.delegatedIndexes = ('Title', 'Description', 'SearchableText')
+ def _getSolrConnection(self) :
+ if not hasattr(self, _VOLATILE_SOLR_NAME) :
+ con = SolrConnection(self.solr_url)
+ setattr(self, _VOLATILE_SOLR_NAME, con)
+ txn = transaction.get()
+ txn.addAfterCommitHook(SolrTransactionHook(self))
+ return getattr(self, _VOLATILE_SOLR_NAME)
+
security.declarePrivate('solrAdd')
def solrAdd(self, object, idxs=[], uid=None) :
if IIndexableObject.providedBy(object):
security.declarePrivate('solrAdd')
def solrAdd(self, object, idxs=[], uid=None) :
if IIndexableObject.providedBy(object):
@@
-61,10
+73,8
@@
class CatalogTool(BaseCatalogTool) :
for name in idxs :
attr = getattr(w, name, '')
data[name] = attr() if callable(attr) else attr
for name in idxs :
attr = getattr(w, name, '')
data[name] = attr() if callable(attr) else attr
- c =
SolrConnection(self.solr_url
)
+ c =
self._getSolrConnection(
)
c.add(**data)
c.add(**data)
- txn = transaction.get()
- txn.addAfterCommitHook(SolrTransactionHook(c))
# PortalCatalog api overloads
# PortalCatalog api overloads
@@
-95,11
+105,9
@@
class CatalogTool(BaseCatalogTool) :
"""Remove from catalog.
"""
super(CatalogTool, self).unindexObject(object)
"""Remove from catalog.
"""
super(CatalogTool, self).unindexObject(object)
- c =
SolrConnection(self.solr_url
)
+ c =
self._getSolrConnection(
)
url = self.__url(object)
c.delete(id=url)
url = self.__url(object)
c.delete(id=url)
- txn = transaction.get()
- txn.addAfterCommitHook(SolrTransactionHook(c))
InitializeClass(CatalogTool)
InitializeClass(CatalogTool)