Made changes to idmapper that might help alleviate issue101 (more people need to run it to make sure). Moved around default command modules to be more logically named and distributed.
This commit is contained in:
parent
19dd476115
commit
3f703efc2d
17 changed files with 1920 additions and 1851 deletions
|
|
@ -73,7 +73,7 @@ class Command(object):
|
|||
# access to this command.
|
||||
permissions = []
|
||||
# used by the help system to group commands in lists.
|
||||
help_category = "default"
|
||||
help_category = "general"
|
||||
# There is also the property 'obj'. This gets set by the system
|
||||
# on the fly to tie this particular command to a certain in-game entity.
|
||||
# self.obj should NOT be defined here since it will not be overwritten
|
||||
|
|
|
|||
|
|
@ -736,3 +736,12 @@ class ObjectDB(TypedObject):
|
|||
|
||||
# Deferred import to avoid circular import errors.
|
||||
from src.commands import cmdhandler
|
||||
|
||||
|
||||
# from src.typeclasses import idmap
|
||||
# class CachedObj(models.Model):
|
||||
# key = models.CharField(max_length=255, null=True, blank=True)
|
||||
# test = models.BooleanField(default=False)
|
||||
# objects = idmap.CachingManager()
|
||||
# def id(self):
|
||||
# return id(self)
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ class ValidateScripts(Script):
|
|||
|
||||
def at_repeat(self):
|
||||
"called every hour"
|
||||
print "ValidateScripts run."
|
||||
#print "ValidateScripts run."
|
||||
ScriptDB.objects.validate()
|
||||
|
||||
class ValidateChannelHandler(Script):
|
||||
|
|
@ -262,7 +262,7 @@ class ValidateChannelHandler(Script):
|
|||
|
||||
def at_repeat(self):
|
||||
"called every hour+"
|
||||
print "ValidateChannelHandler run."
|
||||
#print "ValidateChannelHandler run."
|
||||
channelhandler.CHANNELHANDLER.update()
|
||||
|
||||
class AddCmdSet(Script):
|
||||
|
|
@ -308,9 +308,7 @@ class AddCmdSet(Script):
|
|||
"""
|
||||
This removes the cmdset when the script stops
|
||||
"""
|
||||
cmdset = self.db.cmdset
|
||||
|
||||
print "AddCmdSets: at_stop() for %s called." % self.obj
|
||||
cmdset = self.db.cmdset
|
||||
if cmdset:
|
||||
if self.db.add_default:
|
||||
self.obj.cmdset.delete_default()
|
||||
|
|
|
|||
|
|
@ -424,6 +424,7 @@ INSTALLED_APPS = (
|
|||
'src.permissions',
|
||||
'game.web.news',
|
||||
'game.web.website',)
|
||||
|
||||
# The user profile extends the User object with more functionality;
|
||||
# This should usually not be changed.
|
||||
AUTH_PROFILE_MODULE = "players.PlayerDB"
|
||||
|
|
@ -439,3 +440,9 @@ try:
|
|||
INSTALLED_APPS = INSTALLED_APPS + ('django_extensions',)
|
||||
except ImportError:
|
||||
pass
|
||||
# South handles automatic database scheme migrations when evennia updates
|
||||
#try:
|
||||
# import south
|
||||
# INSTALLED_APPS = INSTALLED_APPS + ('south',)
|
||||
#except ImportError:
|
||||
# pass
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ abstract models in dbobjects.py (and which are thus shared by
|
|||
all Attributes and TypedObjects).
|
||||
"""
|
||||
from django.db import models
|
||||
from src.utils import idmapper
|
||||
#from src.typeclasses import idmap
|
||||
|
||||
# Managers
|
||||
|
||||
|
|
@ -76,7 +78,10 @@ def returns_typeclass(method):
|
|||
return None
|
||||
return func
|
||||
|
||||
class TypedObjectManager(models.Manager):
|
||||
|
||||
#class TypedObjectManager(idmap.CachingManager):
|
||||
#class TypedObjectManager(models.Manager):
|
||||
class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||
"""
|
||||
Common ObjectManager for all dbobjects.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -958,8 +958,3 @@ class TypedObject(SharedMemoryModel):
|
|||
"Stop accidental deletion."
|
||||
raise Exception("Cannot delete the ndb object!")
|
||||
ndb = property(ndb_get, ndb_set, ndb_del)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from weakref import WeakValueDictionary
|
||||
from weakref import WeakValueDictionary, ref
|
||||
|
||||
from django.db.models.base import Model, ModelBase
|
||||
|
||||
from manager import SharedMemoryManager
|
||||
|
||||
TCACHE = {}
|
||||
|
||||
class SharedMemoryModelBase(ModelBase):
|
||||
def __new__(cls, name, bases, attrs):
|
||||
super_new = super(ModelBase, cls).__new__
|
||||
|
|
@ -37,7 +39,7 @@ class SharedMemoryModelBase(ModelBase):
|
|||
return cached_instance
|
||||
|
||||
def _prepare(cls):
|
||||
cls.__instance_cache__ = WeakValueDictionary()
|
||||
cls.__instance_cache__ = {} #WeakValueDictionary()
|
||||
super(SharedMemoryModelBase, cls)._prepare()
|
||||
|
||||
|
||||
|
|
@ -91,7 +93,11 @@ class SharedMemoryModel(Model):
|
|||
Method to store an instance in the cache.
|
||||
"""
|
||||
if instance._get_pk_val() is not None:
|
||||
cls.__instance_cache__[instance._get_pk_val()] = instance
|
||||
cls.__instance_cache__[instance._get_pk_val()] = instance
|
||||
#key = "%s-%s" % (cls, instance.pk)
|
||||
#TCACHE[key] = instance
|
||||
#print "cached: %s (%s: %s) (total cached: %s)" % (instance, cls.__name__, len(cls.__instance_cache__), len(TCACHE))
|
||||
|
||||
cache_instance = classmethod(cache_instance)
|
||||
|
||||
def _flush_cached_by_key(cls, key):
|
||||
|
|
@ -104,6 +110,10 @@ class SharedMemoryModel(Model):
|
|||
since this is most likely called from delete(), and we want to make sure we don't cache dead objects.
|
||||
"""
|
||||
cls._flush_cached_by_key(instance._get_pk_val())
|
||||
#key = "%s-%s" % (cls, instance.pk)
|
||||
#del TCACHE[key]
|
||||
#print "uncached: %s (%s: %s) (total cached: %s)" % (instance, cls.__name__, len(cls.__instance_cache__), len(TCACHE))
|
||||
|
||||
flush_cached_instance = classmethod(flush_cached_instance)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
@ -126,4 +136,4 @@ pre_delete.connect(flush_singleton_cache)
|
|||
# def update_singleton_cache(sender, instance, **kwargs):
|
||||
# if isinstance(instance.__class__, SharedMemoryModel):
|
||||
# instance.__class__.cache_instance(instance)
|
||||
# post_save.connect(flush_singleton_cache)
|
||||
# post_save.connect(flush_singleton_cache)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue