server/sources/__init__.py
changeset 1251 af40e615dc89
parent 1250 5c20a7f13c84
child 1263 01152fffd593
equal deleted inserted replaced
1250:5c20a7f13c84 1251:af40e615dc89
     9 from logging import getLogger
     9 from logging import getLogger
    10 
    10 
    11 from mx.DateTime import now, DateTimeDelta
    11 from mx.DateTime import now, DateTimeDelta
    12 
    12 
    13 from cubicweb import set_log_methods
    13 from cubicweb import set_log_methods
       
    14 from cubicweb.server.sqlutils import SQL_PREFIX
       
    15 
    14 
    16 
    15 class TimedCache(dict):
    17 class TimedCache(dict):
    16     def __init__(self, ttlm, ttls=0):
    18     def __init__(self, ttlm, ttls=0):
    17         # time to live in minutes
    19         # time to live in minutes
    18         self.ttl = DateTimeDelta(0, 0, ttlm, ttls)
    20         self.ttl = DateTimeDelta(0, 0, ttlm, ttls)
    76     def clear_eid_cache(self, eid, etype):
    78     def clear_eid_cache(self, eid, etype):
    77         """clear potential caches for the given eid"""
    79         """clear potential caches for the given eid"""
    78         pass
    80         pass
    79     
    81     
    80     def __repr__(self):
    82     def __repr__(self):
    81         return '<%s source>' % self.uri
    83         return '<%s source @%#x>' % (self.uri, id(self))
    82 
    84 
    83     def __cmp__(self, other):
    85     def __cmp__(self, other):
    84         """simple comparison function to get predictable source order, with the
    86         """simple comparison function to get predictable source order, with the
    85         system source at last
    87         system source at last
    86         """
    88         """
   157                                 {'uri': self.uri})
   159                                 {'uri': self.uri})
   158         myeids = ','.join(str(r[0]) for r in cu.fetchall())
   160         myeids = ','.join(str(r[0]) for r in cu.fetchall())
   159         if not myeids:
   161         if not myeids:
   160             return
   162             return
   161         # delete relations referencing one of those eids
   163         # delete relations referencing one of those eids
       
   164         eidcolum = SQL_PREFIX + 'eid'
   162         for rschema in self.schema.relations():
   165         for rschema in self.schema.relations():
   163             if rschema.is_final() or rschema.type == 'identity':
   166             if rschema.is_final() or rschema.type == 'identity':
   164                 continue
   167                 continue
   165             if rschema.inlined:
   168             if rschema.inlined:
       
   169                 column = SQL_PREFIX + rschema.type
   166                 for subjtype in rschema.subjects():
   170                 for subjtype in rschema.subjects():
       
   171                     table = SQL_PREFIX + str(subjtype)
   167                     for objtype in rschema.objects(subjtype):
   172                     for objtype in rschema.objects(subjtype):
   168                         if self.support_entity(objtype):
   173                         if self.support_entity(objtype):
   169                             sql = 'UPDATE %s SET %s = NULL WHERE eid IN (%s);' % (
   174                             sql = 'UPDATE %s SET %s=NULL WHERE %s IN (%s);' % (
   170                                 subjtype, rschema.type, myeids)
   175                                 table, column, eidcolum, myeids)
   171                             session.system_sql(sql)
   176                             session.system_sql(sql)
   172                             break
   177                             break
   173                 continue
   178                 continue
   174             for etype in rschema.subjects():
   179             for etype in rschema.subjects():
   175                 if self.support_entity(etype):
   180                 if self.support_entity(etype):