From a4cb4d96face514924387d34746b3148848ac092 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Wed, 9 Jul 2014 10:16:16 +0200 Subject: [PATCH] =?utf8?q?Bugfix=C2=A0:=20la=20connexion=20Solr=20peut=20s?= =?utf8?q?e=20volatiliser=20plus=20vite=20que=20le=20hook=20de=20transacti?= =?utf8?q?on=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- catalog.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/catalog.py b/catalog.py index 05cbd59..0a457f8 100644 --- a/catalog.py +++ b/catalog.py @@ -22,17 +22,20 @@ _VOLATILE_SOLR_NAME = '_v_solrConnection' class SolrTransactionHook : ''' commit solr couplé sur le commit de la ZODB ''' - def __init__(self, context) : + def __init__(self, context, con) : self.context = context + self.con = con def __call__(self, status) : - con = getattr(self.context, _VOLATILE_SOLR_NAME) if status : - con.commit() - con.close() + self.con.commit() + self.con.close() else : - con.close() - delattr(self.context, _VOLATILE_SOLR_NAME) + self.con.close() + try : + delattr(self.context, _VOLATILE_SOLR_NAME) + except AttributeError : + pass class CatalogTool(BaseCatalogTool) : meta_type = 'Plinn Catalog' @@ -54,7 +57,7 @@ class CatalogTool(BaseCatalogTool) : con = SolrConnection(self.solr_url) setattr(self, _VOLATILE_SOLR_NAME, con) txn = transaction.get() - txn.addAfterCommitHook(SolrTransactionHook(self)) + txn.addAfterCommitHook(SolrTransactionHook(self, con)) return getattr(self, _VOLATILE_SOLR_NAME) security.declarePrivate('solrAdd') -- 2.20.1