Implement a more throughough cache-flush mechanism. This makes sure to flush foreignkey cache relations for objects not affected by flushing (normally objects with an NAttribute stored in them). Without ForeignKey flushing, the location of such objects would remain cached and drift out of sync, leading to content caches in turn desyncing. Resolves #1064.

This commit is contained in:
Griatch 2016-10-02 20:21:29 +02:00
parent 15025c0586
commit 2b35140fe3
3 changed files with 15 additions and 15 deletions

View file

@ -22,7 +22,7 @@ from django.core.exceptions import ObjectDoesNotExist
from evennia.typeclasses.models import TypedObject
from evennia.objects.manager import ObjectDBManager
from evennia.utils import logger
from evennia.utils.utils import (make_iter, dbref, lazy_property, calledby)
from evennia.utils.utils import (make_iter, dbref, lazy_property)
class ContentsHandler(object):
@ -51,10 +51,8 @@ class ContentsHandler(object):
Re-initialize the content cache
"""
#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, id(self._pkcache), id(self)
def get(self, exclude=None):
"""
@ -70,15 +68,12 @@ 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, 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
self.init()
try:
return [self._idcache[pk] for pk in pks]
@ -96,7 +91,6 @@ class ContentsHandler(object):
"""
self._pkcache[obj.pk] = None
#print "add self._pkcache:", self.obj, obj, obj.pk, self._pkcache
def remove(self, obj):
"""
@ -107,7 +101,6 @@ class ContentsHandler(object):
"""
self._pkcache.pop(obj.pk, None)
#print "remove self._pkcache", self.obj, obj, obj.pk, self._pkcache
def clear(self):
"""
@ -116,7 +109,6 @@ class ContentsHandler(object):
"""
self._pkcache = {}
self.init()
#print "clear _pkcache", self.obj, self._pkcache
#------------------------------------------------------------
#
@ -272,12 +264,10 @@ class ObjectDB(TypedObject):
# remove the safe flag
del self._safe_contents_update
#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
self.db_location.contents_cache.add(self)
except RuntimeError: