server/sources/native.py
changeset 9802 9f815b1f2516
parent 9770 112c884b2d8d
child 9821 2077c8da1893
child 9932 c493767679b2
equal deleted inserted replaced
9800:029f9eafe574 9802:9f815b1f2516
   886     _handle_insert_entity_sql = doexec
   886     _handle_insert_entity_sql = doexec
   887     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   887     _handle_is_instance_of_sql = _handle_source_relation_sql = _handle_is_relation_sql
   888 
   888 
   889     def add_info(self, cnx, entity, source, extid):
   889     def add_info(self, cnx, entity, source, extid):
   890         """add type and source info for an eid into the system table"""
   890         """add type and source info for an eid into the system table"""
   891         with cnx.ensure_cnx_set:
   891         assert cnx.cnxset is not None
   892             # begin by inserting eid/type/source/extid into the entities table
   892         # begin by inserting eid/type/source/extid into the entities table
   893             if extid is not None:
   893         if extid is not None:
   894                 assert isinstance(extid, str)
   894             assert isinstance(extid, str)
   895                 extid = b64encode(extid)
   895             extid = b64encode(extid)
   896             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   896         attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
   897                      'asource': source.uri}
   897                  'asource': source.uri}
   898             self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
   898         self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
   899             # insert core relations: is, is_instance_of and cw_source
   899         # insert core relations: is, is_instance_of and cw_source
   900             try:
   900         try:
   901                 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   901             self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
   902                                              (entity.eid, eschema_eid(cnx, entity.e_schema)))
   902                                          (entity.eid, eschema_eid(cnx, entity.e_schema)))
   903             except IndexError:
   903         except IndexError:
   904                 # during schema serialization, skip
   904             # during schema serialization, skip
   905                 pass
   905             pass
   906             else:
   906         else:
   907                 for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   907             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
   908                     self._handle_is_relation_sql(cnx,
   908                 self._handle_is_relation_sql(cnx,
   909                                                  'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
   909                                              'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
   910                                                  (entity.eid, eschema_eid(cnx, eschema)))
   910                                              (entity.eid, eschema_eid(cnx, eschema)))
   911             if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   911         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
   912                 self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
   912             self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
   913                                              (entity.eid, source.eid))
   913                                          (entity.eid, source.eid))
   914             # now we can update the full text index
   914         # now we can update the full text index
   915             if self.do_fti and self.need_fti_indexation(entity.cw_etype):
   915         if self.do_fti and self.need_fti_indexation(entity.cw_etype):
   916                 self.index_entity(cnx, entity=entity)
   916             self.index_entity(cnx, entity=entity)
   917 
   917 
   918     def update_info(self, cnx, entity, need_fti_update):
   918     def update_info(self, cnx, entity, need_fti_update):
   919         """mark entity as being modified, fulltext reindex if needed"""
   919         """mark entity as being modified, fulltext reindex if needed"""
   920         if self.do_fti and need_fti_update:
   920         if self.do_fti and need_fti_update:
   921             # reindex the entity only if this query is updating at least
   921             # reindex the entity only if this query is updating at least