consider .do_fti flag in index_entity method
as this method may be used from outsite the class (eg in UpdateFTIHook), this is
the proper way to consider it anyway.
Closes #6206636
--- a/server/sources/native.py Tue Jul 21 18:17:31 2015 +0200
+++ b/server/sources/native.py Fri Aug 21 11:01:08 2015 +0200
@@ -916,12 +916,12 @@
self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
(entity.eid, source.eid))
# now we can update the full text index
- if self.do_fti and self.need_fti_indexation(entity.cw_etype):
+ if self.need_fti_indexation(entity.cw_etype):
self.index_entity(cnx, entity=entity)
def update_info(self, cnx, entity, need_fti_update):
"""mark entity as being modified, fulltext reindex if needed"""
- if self.do_fti and need_fti_update:
+ if need_fti_update:
# reindex the entity only if this query is updating at least
# one indexable attribute
self.index_entity(cnx, entity=entity)
@@ -1319,7 +1319,8 @@
"""create an operation to [re]index textual content of the given entity
on commit
"""
- FTIndexEntityOp.get_instance(cnx).add_data(entity.eid)
+ if self.do_fti:
+ FTIndexEntityOp.get_instance(cnx).add_data(entity.eid)
def fti_unindex_entities(self, cnx, entities):
"""remove text content for entities from the full text index
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/test/unittest_sources_native.py Fri Aug 21 11:01:08 2015 +0200
@@ -0,0 +1,38 @@
+# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
+
+from logilab.common import tempattr
+
+from cubicweb.devtools.testlib import CubicWebTC
+from cubicweb.server.sources.native import FTIndexEntityOp
+
+class NativeSourceTC(CubicWebTC):
+
+ def test_index_entity_consider_do_fti(self):
+ source = self.repo.system_source
+ with tempattr(source, 'do_fti', False):
+ with self.admin_access.repo_cnx() as cnx:
+ # when do_fti is set to false, call to index_entity (as may be done from hooks)
+ # should have no effect
+ source.index_entity(cnx, cnx.user)
+ self.assertNotIn(cnx.user.eid, FTIndexEntityOp.get_instance(cnx).get_data())
+
+
+if __name__ == '__main__':
+ from logilab.common.testlib import unittest_main
+ unittest_main()