Removed FULL_PERSISTENCE setting. It was a "feature" that was added at a time when caching was more inefficient than now. Also the new reload mechanism make FULL_PERSISTENCE=False unfeasable. Use ndb explicitly for non-persistence.

This commit is contained in:
Griatch 2011-10-01 15:10:21 +02:00
parent 679524bd4a
commit 0a1bcd36c2
4 changed files with 12 additions and 40 deletions

View file

@ -33,7 +33,6 @@ from src.utils.utils import is_iter, to_unicode, to_str, mod_import
#PlayerDB = ContentType.objects.get(app_label="players", model="playerdb").model_class()
FULL_PERSISTENCE = settings.FULL_PERSISTENCE
AT_SEARCH_RESULT = mod_import(*settings.SEARCH_AT_RESULT.rsplit('.', 1))
#------------------------------------------------------------

View file

@ -52,17 +52,6 @@ SSL_ENABLED = False
SSL_PORTS = [4001]
# Interface addresses to listen to. If 0.0.0.0, listen to all.
SSL_INTERFACES = ['0.0.0.0']
# Activate full persistence if you want everything in-game to be
# stored to the database. With it set, you can do typeclass.attr=value
# and value will be saved to the database under the name 'attr'.
# This is easy but may be a performance hit for certain game types.
# Turning it off gives more control over what hits the database since
# typeclass.attr=value is then non-persistent (does not hit the
# database and won't survive a server reload) and you need to
# explicitly do typeclass.db.attr = value if you want to save your
# value to the database. Your choice, but DON'T change this
# value once you have started using the server, it will not end well!
FULL_PERSISTENCE = True
# If multisessions are allowed, a user can log into the game
# from several different computers/clients at the same time.
# All feedback from the game will be echoed to all sessions.

View file

@ -995,9 +995,7 @@ class TypedObject(SharedMemoryModel):
#
# Fully persistent attributes. You usually access these
# through the obj.db.attrname method. If FULL_PERSISTENCE
# is set, you will access these by just obj.attrname instead.
#
# through the obj.db.attrname method.
# Helper methods for persistent attributes
@ -1176,9 +1174,8 @@ class TypedObject(SharedMemoryModel):
db = property(db_get, db_set, db_del)
#
# NON-PERSISTENT store. If you run FULL_PERSISTENT but still
# want to save something and be sure it's cleared on a server
# reboot, you should use this explicitly. Otherwise there is
# NON-PERSISTENT store. If you want to loose data on server reboot
# you should use this explicitly. Otherwise there is
# little point in using the non-persistent methods.
#
@ -1212,9 +1209,8 @@ class TypedObject(SharedMemoryModel):
"""
A non-persistent store (ndb: NonDataBase). Everything stored
to this is guaranteed to be cleared when a server is shutdown.
Works also if FULL_PERSISTENCE is active. Syntax is as for
the _get_db_holder() method and property,
e.g. obj.ndb.attr = value etc.
Syntax is same as for the _get_db_holder() method and
property, e.g. obj.ndb.attr = value etc.
"""
try:
return self._ndb_holder

View file

@ -24,10 +24,6 @@ PROTECTED = ['id', 'dbobj', 'db', 'ndb', 'objects', 'typeclass',
# If this is true, all non-protected property assignments
# are directly stored to a database attribute
try:
FULL_PERSISTENCE = settings.FULL_PERSISTENCE
except AttributeError:
FULL_PERSISTENCE = True
class MetaTypeClass(type):
"""
@ -120,13 +116,13 @@ class TypeClass(object):
return object.__getattribute__(dbobj, propname)
except AttributeError:
try:
if FULL_PERSISTENCE and propname != 'ndb':
if propname != 'ndb':
if not dbobj.has_attribute(propname):
raise AttributeError
else:
value = dbobj.get_attribute(propname)
else:
# Not FULL_PERSISTENCE
# get non-persistent data
ndb = object.__getattribute__(dbobj, 'ndb')
value = getattr(ndb, propname)
return value
@ -165,12 +161,8 @@ class TypeClass(object):
if hasattr(dbobj, propname):
# only if attr already exists on dbobj, assign to it.
object.__setattr__(dbobj, propname, value)
elif FULL_PERSISTENCE:
else:
dbobj.set_attribute(propname, value)
else:
# not FULL_PERSISTENCE
ndb = object.__getattribute__(dbobj, 'ndb')
setattr(ndb, propname, value)
else:
object.__setattr__(self, propname, value)
@ -187,7 +179,7 @@ class TypeClass(object):
def __delattr__(self, propname):
"""
Transparently deletes data from the typeclass or dbobj by first searching on the typeclass,
secondly on the dbobj.db or ndb depending on FULL_PERSISTENCE setting.
secondly on the dbobj.db.
Will not allow deletion of properties stored directly on dbobj.
"""
try:
@ -210,13 +202,9 @@ class TypeClass(object):
logger.log_trace("This is probably due to an unsafe reload.")
return # ignore delete
try:
if FULL_PERSISTENCE:
if not dbobj.has_attribute(propname):
raise AttributeError
dbobj.del_attribute(propname)
else:
ndb = object.__getattribute__(dbobj, 'ndb')
ndb.__delattr__(propname)
if not dbobj.has_attribute(propname):
raise AttributeError
dbobj.del_attribute(propname)
except AttributeError:
string = "Object: '%s' not found on %s(%s), nor on its typeclass %s."
raise AttributeError(string % (propname, dbobj,