server/repository.py
branchstable
changeset 7373 e5e6ef56cfb5
parent 7305 1f97c05cfbab
child 7398 26695dd703d8
child 7501 2983dd24494a
equal deleted inserted replaced
7372:65bd75f16d65 7373:e5e6ef56cfb5
    57 from cubicweb.server import utils, hook, pool, querier, sources
    57 from cubicweb.server import utils, hook, pool, querier, sources
    58 from cubicweb.server.session import Session, InternalSession, InternalManager, \
    58 from cubicweb.server.session import Session, InternalSession, InternalManager, \
    59      security_enabled
    59      security_enabled
    60 from cubicweb.server.ssplanner import EditedEntity
    60 from cubicweb.server.ssplanner import EditedEntity
    61 
    61 
       
    62 NO_CACHE_RELATIONS = set( [('require_permission', 'object'),
       
    63                            ('owned_by', 'object'),
       
    64                            ('created_by', 'object'),
       
    65                            ('cw_source', 'object'),
       
    66                            ])
    62 
    67 
    63 def prefill_entity_caches(entity, relations):
    68 def prefill_entity_caches(entity, relations):
    64     session = entity._cw
    69     session = entity._cw
    65     # prefill entity relation caches
    70     # prefill entity relation caches
    66     for rschema in entity.e_schema.subject_relations():
    71     for rschema in entity.e_schema.subject_relations():
    67         rtype = str(rschema)
    72         rtype = str(rschema)
    68         if rtype in schema.VIRTUAL_RTYPES:
    73         if rtype in schema.VIRTUAL_RTYPES or (rtype, 'subject') in NO_CACHE_RELATIONS:
    69             continue
    74             continue
    70         if rschema.final:
    75         if rschema.final:
    71             entity.cw_attr_cache.setdefault(rtype, None)
    76             entity.cw_attr_cache.setdefault(rtype, None)
    72         else:
    77         else:
    73             entity.cw_set_relation_cache(rtype, 'subject',
    78             entity.cw_set_relation_cache(rtype, 'subject',
    74                                          session.empty_rset())
    79                                          session.empty_rset())
    75     for rschema in entity.e_schema.object_relations():
    80     for rschema in entity.e_schema.object_relations():
    76         rtype = str(rschema)
    81         rtype = str(rschema)
    77         if rtype in schema.VIRTUAL_RTYPES:
    82         if rtype in schema.VIRTUAL_RTYPES or (rtype, 'object') in NO_CACHE_RELATIONS:
    78             continue
    83             continue
    79         entity.cw_set_relation_cache(rtype, 'object', session.empty_rset())
    84         entity.cw_set_relation_cache(rtype, 'object', session.empty_rset())
    80     # set inlined relation cache before call to after_add_entity
    85     # set inlined relation cache before call to after_add_entity
    81     for attr, value in relations:
    86     for attr, value in relations:
    82         session.update_rel_cache_add(entity.eid, attr, value)
    87         session.update_rel_cache_add(entity.eid, attr, value)