192 self._cache = Cache(repo.config['rql-cache-size']) |
192 self._cache = Cache(repo.config['rql-cache-size']) |
193 self._temp_table_data = {} |
193 self._temp_table_data = {} |
194 self._eid_creation_lock = Lock() |
194 self._eid_creation_lock = Lock() |
195 # (etype, attr) / storage mapping |
195 # (etype, attr) / storage mapping |
196 self._storages = {} |
196 self._storages = {} |
|
197 # entity types that may be used by other multi-sources instances |
|
198 self.multisources_etypes = set(repo.config['multi-sources-etypes']) |
197 # XXX no_sqlite_wrap trick since we've a sqlite locking pb when |
199 # XXX no_sqlite_wrap trick since we've a sqlite locking pb when |
198 # running unittest_multisources with the wrapping below |
200 # running unittest_multisources with the wrapping below |
199 if self.dbdriver == 'sqlite' and \ |
201 if self.dbdriver == 'sqlite' and \ |
200 not getattr(repo.config, 'no_sqlite_wrap', False): |
202 not getattr(repo.config, 'no_sqlite_wrap', False): |
201 from cubicweb.server.sources.extlite import ConnectionWrapper |
203 from cubicweb.server.sources.extlite import ConnectionWrapper |
657 """mark entity as being modified, fulltext reindex if needed""" |
659 """mark entity as being modified, fulltext reindex if needed""" |
658 if self.do_fti and need_fti_update: |
660 if self.do_fti and need_fti_update: |
659 # reindex the entity only if this query is updating at least |
661 # reindex the entity only if this query is updating at least |
660 # one indexable attribute |
662 # one indexable attribute |
661 FTIndexEntityOp(session, entity=entity) |
663 FTIndexEntityOp(session, entity=entity) |
662 # update entities.mtime |
664 # update entities.mtime. |
|
665 # XXX Only if entity.__regid__ in self.multisources_etypes? |
663 attrs = {'eid': entity.eid, 'mtime': datetime.now()} |
666 attrs = {'eid': entity.eid, 'mtime': datetime.now()} |
664 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
667 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
665 |
668 |
666 def delete_info(self, session, entity, uri, extid): |
669 def delete_info(self, session, entity, uri, extid): |
667 """delete system information on deletion of an entity by transfering |
670 """delete system information on deletion of an entity: |
668 record from the entities table to the deleted_entities table |
671 * remove record from the entities table |
|
672 * transfer it to the deleted_entities table if the entity's type is |
|
673 multi-sources |
669 """ |
674 """ |
670 attrs = {'eid': entity.eid} |
675 attrs = {'eid': entity.eid} |
671 self.doexec(session, self.sqlgen.delete('entities', attrs), attrs) |
676 self.doexec(session, self.sqlgen.delete('entities', attrs), attrs) |
|
677 if not entity.__regid__ in self.multisources_etypes: |
|
678 return |
672 if extid is not None: |
679 if extid is not None: |
673 assert isinstance(extid, str), type(extid) |
680 assert isinstance(extid, str), type(extid) |
674 extid = b64encode(extid) |
681 extid = b64encode(extid) |
675 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
682 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
676 'source': uri, 'dtime': datetime.now(), |
683 'source': uri, 'dtime': datetime.now(), |
683 modified since the given timestamp (actually entities whose full text |
690 modified since the given timestamp (actually entities whose full text |
684 index content has changed) |
691 index content has changed) |
685 * list of (etype, eid) of entities of the given types which have been |
692 * list of (etype, eid) of entities of the given types which have been |
686 deleted since the given timestamp |
693 deleted since the given timestamp |
687 """ |
694 """ |
|
695 for etype in etypes: |
|
696 if not etype in self.multisources_etypes: |
|
697 self.critical('%s not listed as a multi-sources entity types. ' |
|
698 'Modify your configuration') |
|
699 self.multisources_etypes.add(etype) |
688 modsql = _modified_sql('entities', etypes) |
700 modsql = _modified_sql('entities', etypes) |
689 cursor = self.doexec(session, modsql, {'time': mtime}) |
701 cursor = self.doexec(session, modsql, {'time': mtime}) |
690 modentities = cursor.fetchall() |
702 modentities = cursor.fetchall() |
691 delsql = _modified_sql('deleted_entities', etypes) |
703 delsql = _modified_sql('deleted_entities', etypes) |
692 cursor = self.doexec(session, delsql, {'time': mtime}) |
704 cursor = self.doexec(session, delsql, {'time': mtime}) |
929 action.changes['cw_eid'] = eid |
941 action.changes['cw_eid'] = eid |
930 sql = self.sqlgen.insert(SQL_PREFIX + etype, action.changes) |
942 sql = self.sqlgen.insert(SQL_PREFIX + etype, action.changes) |
931 self.doexec(session, sql, action.changes) |
943 self.doexec(session, sql, action.changes) |
932 # restore record in entities (will update fti if needed) |
944 # restore record in entities (will update fti if needed) |
933 self.add_info(session, entity, self, None, True) |
945 self.add_info(session, entity, self, None, True) |
934 # remove record from deleted_entities |
946 # remove record from deleted_entities if entity's type is multi-sources |
935 self.doexec(session, 'DELETE FROM deleted_entities WHERE eid=%s' % eid) |
947 if entity.__regid__ in self.multisources_etypes: |
|
948 self.doexec(session, |
|
949 'DELETE FROM deleted_entities WHERE eid=%s' % eid) |
936 self.repo.hm.call_hooks('after_add_entity', session, entity=entity) |
950 self.repo.hm.call_hooks('after_add_entity', session, entity=entity) |
937 return errors |
951 return errors |
938 |
952 |
939 def _undo_r(self, session, action): |
953 def _undo_r(self, session, action): |
940 """undo a relation removal""" |
954 """undo a relation removal""" |