server/checkintegrity.py
changeset 9574 2d4c4842bd04
parent 9543 39f981482e34
child 9577 c52441e4a3d7
equal deleted inserted replaced
9573:99166335a8e0 9574:2d4c4842bd04
    80                 for container in etype_fti_containers(targeteschema, _done):
    80                 for container in etype_fti_containers(targeteschema, _done):
    81                     yield container
    81                     yield container
    82     else:
    82     else:
    83         yield eschema
    83         yield eschema
    84 
    84 
    85 def reindex_entities(schema, session, withpb=True, etypes=None):
    85 def reindex_entities(schema, cnx, withpb=True, etypes=None):
    86     """reindex all entities in the repository"""
    86     """reindex all entities in the repository"""
    87     # deactivate modification_date hook since we don't want them
    87     # deactivate modification_date hook since we don't want them
    88     # to be updated due to the reindexation
    88     # to be updated due to the reindexation
    89     repo = session.repo
    89     repo = cnx.repo
    90     cursor = session.cnxset.cu
    90     cursor = cnx.cnxset.cu
    91     dbhelper = session.repo.system_source.dbhelper
    91     dbhelper = repo.system_source.dbhelper
    92     if not dbhelper.has_fti_table(cursor):
    92     if not dbhelper.has_fti_table(cursor):
    93         print 'no text index table'
    93         print 'no text index table'
    94         dbhelper.init_fti(cursor)
    94         dbhelper.init_fti(cursor)
    95     repo.system_source.do_fti = True  # ensure full-text indexation is activated
    95     repo.system_source.do_fti = True  # ensure full-text indexation is activated
    96     if etypes is None:
    96     if etypes is None:
   103             if not indexable_attrs:
   103             if not indexable_attrs:
   104                 continue
   104                 continue
   105             for container in etype_fti_containers(eschema):
   105             for container in etype_fti_containers(eschema):
   106                 etypes.add(container)
   106                 etypes.add(container)
   107         # clear fti table first
   107         # clear fti table first
   108         session.system_sql('DELETE FROM %s' % dbhelper.fti_table)
   108         cnx.system_sql('DELETE FROM %s' % dbhelper.fti_table)
   109     else:
   109     else:
   110         print 'Reindexing entities of type %s' % \
   110         print 'Reindexing entities of type %s' % \
   111               ', '.join(sorted(str(e) for e in etypes))
   111               ', '.join(sorted(str(e) for e in etypes))
   112         # clear fti table first. Use subquery for sql compatibility
   112         # clear fti table first. Use subquery for sql compatibility
   113         session.system_sql("DELETE FROM %s WHERE EXISTS(SELECT 1 FROM ENTITIES "
   113         cnx.system_sql("DELETE FROM %s WHERE EXISTS(SELECT 1 FROM ENTITIES "
   114                            "WHERE eid=%s AND type IN (%s))" % (
   114                        "WHERE eid=%s AND type IN (%s))" % (
   115                                dbhelper.fti_table, dbhelper.fti_uid_attr,
   115                            dbhelper.fti_table, dbhelper.fti_uid_attr,
   116                                ','.join("'%s'" % etype for etype in etypes)))
   116                            ','.join("'%s'" % etype for etype in etypes)))
   117     if withpb:
   117     if withpb:
   118         pb = ProgressBar(len(etypes) + 1)
   118         pb = ProgressBar(len(etypes) + 1)
   119         pb.update()
   119         pb.update()
   120     # reindex entities by generating rql queries which set all indexable
   120     # reindex entities by generating rql queries which set all indexable
   121     # attribute to their current value
   121     # attribute to their current value
   122     source = repo.system_source
   122     source = repo.system_source
   123     for eschema in etypes:
   123     for eschema in etypes:
   124         etype_class = session.vreg['etypes'].etype_class(str(eschema))
   124         etype_class = cnx.vreg['etypes'].etype_class(str(eschema))
   125         for fti_rql in etype_class.cw_fti_index_rql_queries(session):
   125         for fti_rql in etype_class.cw_fti_index_rql_queries(cnx):
   126             rset = session.execute(fti_rql)
   126             rset = cnx.execute(fti_rql)
   127             source.fti_index_entities(session, rset.entities())
   127             source.fti_index_entities(cnx, rset.entities())
   128             # clear entity cache to avoid high memory consumption on big tables
   128             # clear entity cache to avoid high memory consumption on big tables
   129             session.drop_entity_cache()
   129             cnx.drop_entity_cache()
   130         if withpb:
   130         if withpb:
   131             pb.update()
   131             pb.update()
   132 
   132 
   133 
   133 
   134 def check_schema(schema, session, eids, fix=1):
   134 def check_schema(schema, session, eids, fix=1):