server/repository.py
changeset 6467 869813c2dd40
parent 6466 43d71dd8a8ec
child 6491 ee9a10b6620e
equal deleted inserted replaced
6466:43d71dd8a8ec 6467:869813c2dd40
    52                       UnknownEid, AuthenticationError, ExecutionError,
    52                       UnknownEid, AuthenticationError, ExecutionError,
    53                       ETypeNotSupportedBySources, MultiSourcesError,
    53                       ETypeNotSupportedBySources, MultiSourcesError,
    54                       BadConnectionId, Unauthorized, ValidationError,
    54                       BadConnectionId, Unauthorized, ValidationError,
    55                       RepositoryError, UniqueTogetherError, typed_eid, onevent)
    55                       RepositoryError, UniqueTogetherError, typed_eid, onevent)
    56 from cubicweb import cwvreg, schema, server
    56 from cubicweb import cwvreg, schema, server
    57 from cubicweb.entity import prefill_entity_caches
       
    58 from cubicweb.server import utils, hook, pool, querier, sources
    57 from cubicweb.server import utils, hook, pool, querier, sources
    59 from cubicweb.server.session import Session, InternalSession, InternalManager, \
    58 from cubicweb.server.session import Session, InternalSession, InternalManager, \
    60      security_enabled
    59      security_enabled
    61 from cubicweb.server.ssplanner import EditedEntity
    60 from cubicweb.server.ssplanner import EditedEntity
       
    61 
       
    62 def prefill_entity_caches(entity, relations):
       
    63     session = entity._cw
       
    64     # prefill entity relation caches
       
    65     for rschema in entity.e_schema.subject_relations():
       
    66         rtype = str(rschema)
       
    67         if rtype in schema.VIRTUAL_RTYPES:
       
    68             continue
       
    69         if rschema.final:
       
    70             entity.cw_attr_cache.setdefault(rtype, None)
       
    71         else:
       
    72             entity.cw_set_relation_cache(rtype, 'subject',
       
    73                                          session.empty_rset())
       
    74     for rschema in entity.e_schema.object_relations():
       
    75         rtype = str(rschema)
       
    76         if rtype in schema.VIRTUAL_RTYPES:
       
    77             continue
       
    78         entity.cw_set_relation_cache(rtype, 'object', session.empty_rset())
       
    79     # set inlined relation cache before call to after_add_entity
       
    80     for attr, value in relations:
       
    81         session.update_rel_cache_add(entity.eid, attr, value)
       
    82         del_existing_rel_if_needed(session, entity.eid, attr, value)
    62 
    83 
    63 def del_existing_rel_if_needed(session, eidfrom, rtype, eidto):
    84 def del_existing_rel_if_needed(session, eidfrom, rtype, eidto):
    64     """delete existing relation when adding a new one if card is 1 or ?
    85     """delete existing relation when adding a new one if card is 1 or ?
    65 
    86 
    66     have to be done once the new relation has been inserted to avoid having
    87     have to be done once the new relation has been inserted to avoid having