Added at_idmapper_flush to allow objects more control of their flush characteristics.

This commit is contained in:
Griatch 2016-10-02 19:14:22 +02:00
parent cd616caf29
commit 15025c0586
6 changed files with 74 additions and 33 deletions

View file

@ -51,10 +51,10 @@ class ContentsHandler(object):
Re-initialize the content cache
"""
print "__init__", self.obj, calledby()
#print "__init__", self.obj, calledby()
self._pkcache.update(dict((obj.pk, None) for obj in
ObjectDB.objects.filter(db_location=self.obj) if obj.pk))
print "init contentscache: self._pkcache:", self.obj, self._pkcache
#print "init contentscache: self._pkcache:", self.obj, self._pkcache, id(self._pkcache), id(self)
def get(self, exclude=None):
"""
@ -70,15 +70,15 @@ class ContentsHandler(object):
if exclude:
pks = [pk for pk in self._pkcache if pk not in [excl.pk for excl in make_iter(exclude)]]
else:
print calledby()
print "get: self._pkcache", self.obj, self._pkcache
#print calledby()
#print "get: self._pkcache", self.obj, self._pkcache, id(self._pkcache), id(self)
pks = self._pkcache
try:
return [self._idcache[pk] for pk in pks]
except KeyError, err:
# this can happen if the idmapper cache was cleared for an object
# in the contents cache. If so we need to re-initialize and try again.
print "content_cache.get keyerror:", err, self._pkcache, self._idcache
#print "content_cache.get keyerror:", err, self._pkcache, self._idcache
self.init()
try:
return [self._idcache[pk] for pk in pks]
@ -96,7 +96,7 @@ class ContentsHandler(object):
"""
self._pkcache[obj.pk] = None
print "add self._pkcache:", self.obj, obj, obj.pk, self._pkcache
#print "add self._pkcache:", self.obj, obj, obj.pk, self._pkcache
def remove(self, obj):
"""
@ -107,7 +107,7 @@ class ContentsHandler(object):
"""
self._pkcache.pop(obj.pk, None)
print "remove self._pkcache", self.obj, obj, obj.pk, self._pkcache
#print "remove self._pkcache", self.obj, obj, obj.pk, self._pkcache
def clear(self):
"""
@ -116,7 +116,7 @@ class ContentsHandler(object):
"""
self._pkcache = {}
self.init()
print "clear _pkcache", self.obj, self._pkcache
#print "clear _pkcache", self.obj, self._pkcache
#------------------------------------------------------------
#
@ -272,12 +272,12 @@ class ObjectDB(TypedObject):
# remove the safe flag
del self._safe_contents_update
print "location_set:", self.key, old_location, self.db_location
#print "location_set:", self.key, old_location, self.db_location
# update the contents cache
if old_location:
old_location.contents_cache.remove(self)
if self.db_location:
print "cache add:", self.db_location, self
#print "cache add:", self.db_location, self
self.db_location.contents_cache.add(self)
except RuntimeError:

View file

@ -228,7 +228,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
"""
con = self.contents_cache.get(exclude=exclude)
print "contents_get:", self, con, calledby()
#print "contents_get:", self, con, id(self), calledby()
return con
contents = property(contents_get)
@ -267,7 +267,6 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
return "{}(#{})".format(self.name, self.id)
return self.name
def search(self, searchdata,
global_search=False,
use_nicks=True, # should this default to off?
@ -1134,7 +1133,6 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
"""
pass
# hooks called when moving the object
def at_before_move(self, destination):