server/checkintegrity.py
branchstable
changeset 5954 987086484876
parent 5850 fabff2813ee4
child 5999 eaf8219f8b7d
equal deleted inserted replaced
5942:f7768f44b4ac 5954:987086484876
    92     """reindex all entities in the repository"""
    92     """reindex all entities in the repository"""
    93     # deactivate modification_date hook since we don't want them
    93     # deactivate modification_date hook since we don't want them
    94     # to be updated due to the reindexation
    94     # to be updated due to the reindexation
    95     repo = session.repo
    95     repo = session.repo
    96     cursor = session.pool['system']
    96     cursor = session.pool['system']
    97     if not repo.system_source.dbhelper.has_fti_table(cursor):
    97     dbhelper = session.repo.system_source.dbhelper
       
    98     if not dbhelper.has_fti_table(cursor):
    98         print 'no text index table'
    99         print 'no text index table'
    99         repo.system_source.dbhelper.init_fti(cursor)
   100         dbhelper.init_fti(cursor)
   100     repo.system_source.do_fti = True  # ensure full-text indexation is activated
   101     repo.system_source.do_fti = True  # ensure full-text indexation is activated
       
   102     if withpb:
       
   103         pb = ProgressBar(len(etypes) + 1)
   101     if etypes is None:
   104     if etypes is None:
       
   105         print 'Reindexing entities'
   102         etypes = set()
   106         etypes = set()
   103         for eschema in schema.entities():
   107         for eschema in schema.entities():
   104             if eschema.final:
   108             if eschema.final:
   105                 continue
   109                 continue
   106             indexable_attrs = tuple(eschema.indexable_attributes()) # generator
   110             indexable_attrs = tuple(eschema.indexable_attributes()) # generator
   107             if not indexable_attrs:
   111             if not indexable_attrs:
   108                 continue
   112                 continue
   109             for container in etype_fti_containers(eschema):
   113             for container in etype_fti_containers(eschema):
   110                 etypes.add(container)
   114                 etypes.add(container)
   111     print 'Reindexing entities of type %s' % \
   115         # clear fti table first
   112           ', '.join(sorted(str(e) for e in etypes))
   116         session.system_sql('DELETE FROM %s' % dbhelper.fti_table)
   113     if withpb:
   117     else:
   114         pb = ProgressBar(len(etypes) + 1)
   118         print 'Reindexing entities of type %s' % \
   115     # first monkey patch Entity.check to disable validation
   119               ', '.join(sorted(str(e) for e in etypes))
   116     # clear fti table first
   120         # clear fti table first. Use subquery for sql compatibility
   117     session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table)
   121         session.system_sql("DELETE FROM %s WHERE EXISTS(SELECT 1 FROM ENTITIES "
       
   122                            "WHERE eid=%s AND type IN (%s))" % (
       
   123                                dbhelper.fti_table, dbhelper.fti_uid_attr,
       
   124                                ','.join("'%s'" % etype for etype in etypes)))
   118     if withpb:
   125     if withpb:
   119         pb.update()
   126         pb.update()
   120     # reindex entities by generating rql queries which set all indexable
   127     # reindex entities by generating rql queries which set all indexable
   121     # attribute to their current value
   128     # attribute to their current value
   122     source = repo.system_source
   129     source = repo.system_source