# HG changeset patch # User Sylvain Thénault # Date 1278930524 -7200 # Node ID 1ce09206a3a39ab93aedafc7dec47b01f968b048 # Parent 67dfe437bf25b85190ccbe5d50b35b5a6ee30fa8# Parent 9bfa823735e0e04642687f8bc659d1ad2fa731a7 backport stable diff -r 67dfe437bf25 -r 1ce09206a3a3 .hgtags --- a/.hgtags Mon Jul 12 12:25:19 2010 +0200 +++ b/.hgtags Mon Jul 12 12:28:44 2010 +0200 @@ -137,3 +137,5 @@ 607a90073911b6bb941a49b5ec0b0d2a9cd479af cubicweb-debian-version-3.8.6-1 d9936c39d478b6701a4adef17bc28888ffa011c6 cubicweb-version-3.9.0 eda4940ffef8b7d36127e68de63a52388374a489 cubicweb-debian-version-3.9.0-1 +a1a334d934390043a4293a4ee42bdceb1343246e cubicweb-version-3.8.7 +1cccf88d6dfe42986e1091de4c364b7b5814c54f cubicweb-debian-version-3.8.7-1 diff -r 67dfe437bf25 -r 1ce09206a3a3 server/checkintegrity.py --- a/server/checkintegrity.py Mon Jul 12 12:25:19 2010 +0200 +++ b/server/checkintegrity.py Mon Jul 12 12:28:44 2010 +0200 @@ -94,11 +94,15 @@ # to be updated due to the reindexation repo = session.repo cursor = session.pool['system'] - if not repo.system_source.dbhelper.has_fti_table(cursor): + dbhelper = session.repo.system_source.dbhelper + if not dbhelper.has_fti_table(cursor): print 'no text index table' - repo.system_source.dbhelper.init_fti(cursor) + dbhelper.init_fti(cursor) repo.system_source.do_fti = True # ensure full-text indexation is activated + if withpb: + pb = ProgressBar(len(etypes) + 1) if etypes is None: + print 'Reindexing entities' etypes = set() for eschema in schema.entities(): if eschema.final: @@ -108,13 +112,16 @@ continue for container in etype_fti_containers(eschema): etypes.add(container) - print 'Reindexing entities of type %s' % \ - ', '.join(sorted(str(e) for e in etypes)) - if withpb: - pb = ProgressBar(len(etypes) + 1) - # first monkey patch Entity.check to disable validation - # clear fti table first - session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table) + # clear fti table first + session.system_sql('DELETE FROM %s' % dbhelper.fti_table) + else: + print 'Reindexing entities of type %s' % \ + ', '.join(sorted(str(e) for e in etypes)) + # clear fti table first. Use subquery for sql compatibility + session.system_sql("DELETE FROM %s WHERE EXISTS(SELECT 1 FROM ENTITIES " + "WHERE eid=%s AND type IN (%s))" % ( + dbhelper.fti_table, dbhelper.fti_uid_attr, + ','.join("'%s'" % etype for etype in etypes))) if withpb: pb.update() # reindex entities by generating rql queries which set all indexable diff -r 67dfe437bf25 -r 1ce09206a3a3 server/test/unittest_checkintegrity.py --- a/server/test/unittest_checkintegrity.py Mon Jul 12 12:25:19 2010 +0200 +++ b/server/test/unittest_checkintegrity.py Mon Jul 12 12:28:44 2010 +0200 @@ -15,28 +15,47 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -""" -""" import sys from StringIO import StringIO from logilab.common.testlib import TestCase, unittest_main from cubicweb.devtools import init_test_database -from cubicweb.server.checkintegrity import check +from cubicweb.server.checkintegrity import check, reindex_entities class CheckIntegrityTC(TestCase): - def test(self): - repo, cnx = init_test_database() + def setUp(self): + self.repo, self.cnx = init_test_database() + self.execute = self.cnx.cursor().execute + self.session = self.repo._sessions[self.cnx.sessionid] sys.stderr = sys.stdout = StringIO() - try: - check(repo, cnx, ('entities', 'relations', 'text_index', 'metadata'), - reindex=True, fix=True, withpb=False) - finally: - sys.stderr = sys.__stderr__ - sys.stdout = sys.__stdout__ - repo.shutdown() + + def tearDown(self): + sys.stderr = sys.__stderr__ + sys.stdout = sys.__stdout__ + self.cnx.close() + self.repo.shutdown() + + def test_checks(self): + check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'), + reindex=False, fix=True, withpb=False) + + def test_reindex_all(self): + self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"') + self.session.commit(False) + self.failUnless(self.execute('Any X WHERE X has_text "tutu"')) + reindex_entities(self.repo.schema, self.session, withpb=False) + self.failUnless(self.execute('Any X WHERE X has_text "tutu"')) + + def test_reindex_etype(self): + self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"') + self.execute('INSERT Affaire X: X ref "toto"') + self.session.commit(False) + reindex_entities(self.repo.schema, self.session, withpb=False, + etypes=('Personne',)) + self.failUnless(self.execute('Any X WHERE X has_text "tutu"')) + self.failUnless(self.execute('Any X WHERE X has_text "toto"')) if __name__ == '__main__': unittest_main()