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() #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)) AT_SEARCH_RESULT = mod_import(*settings.SEARCH_AT_RESULT.rsplit('.', 1))
#------------------------------------------------------------ #------------------------------------------------------------

View file

@ -52,17 +52,6 @@ SSL_ENABLED = False
SSL_PORTS = [4001] SSL_PORTS = [4001]
# Interface addresses to listen to. If 0.0.0.0, listen to all. # Interface addresses to listen to. If 0.0.0.0, listen to all.
SSL_INTERFACES = ['0.0.0.0'] 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 # If multisessions are allowed, a user can log into the game
# from several different computers/clients at the same time. # from several different computers/clients at the same time.
# All feedback from the game will be echoed to all sessions. # 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 # Fully persistent attributes. You usually access these
# through the obj.db.attrname method. If FULL_PERSISTENCE # through the obj.db.attrname method.
# is set, you will access these by just obj.attrname instead.
#
# Helper methods for persistent attributes # Helper methods for persistent attributes
@ -1176,9 +1174,8 @@ class TypedObject(SharedMemoryModel):
db = property(db_get, db_set, db_del) db = property(db_get, db_set, db_del)
# #
# NON-PERSISTENT store. If you run FULL_PERSISTENT but still # NON-PERSISTENT store. If you want to loose data on server reboot
# want to save something and be sure it's cleared on a server # you should use this explicitly. Otherwise there is
# reboot, you should use this explicitly. Otherwise there is
# little point in using the non-persistent methods. # little point in using the non-persistent methods.
# #
@ -1212,9 +1209,8 @@ class TypedObject(SharedMemoryModel):
""" """
A non-persistent store (ndb: NonDataBase). Everything stored A non-persistent store (ndb: NonDataBase). Everything stored
to this is guaranteed to be cleared when a server is shutdown. to this is guaranteed to be cleared when a server is shutdown.
Works also if FULL_PERSISTENCE is active. Syntax is as for Syntax is same as for the _get_db_holder() method and
the _get_db_holder() method and property, property, e.g. obj.ndb.attr = value etc.
e.g. obj.ndb.attr = value etc.
""" """
try: try:
return self._ndb_holder 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 # If this is true, all non-protected property assignments
# are directly stored to a database attribute # are directly stored to a database attribute
try:
FULL_PERSISTENCE = settings.FULL_PERSISTENCE
except AttributeError:
FULL_PERSISTENCE = True
class MetaTypeClass(type): class MetaTypeClass(type):
""" """
@ -120,13 +116,13 @@ class TypeClass(object):
return object.__getattribute__(dbobj, propname) return object.__getattribute__(dbobj, propname)
except AttributeError: except AttributeError:
try: try:
if FULL_PERSISTENCE and propname != 'ndb': if propname != 'ndb':
if not dbobj.has_attribute(propname): if not dbobj.has_attribute(propname):
raise AttributeError raise AttributeError
else: else:
value = dbobj.get_attribute(propname) value = dbobj.get_attribute(propname)
else: else:
# Not FULL_PERSISTENCE # get non-persistent data
ndb = object.__getattribute__(dbobj, 'ndb') ndb = object.__getattribute__(dbobj, 'ndb')
value = getattr(ndb, propname) value = getattr(ndb, propname)
return value return value
@ -165,12 +161,8 @@ class TypeClass(object):
if hasattr(dbobj, propname): if hasattr(dbobj, propname):
# only if attr already exists on dbobj, assign to it. # only if attr already exists on dbobj, assign to it.
object.__setattr__(dbobj, propname, value) object.__setattr__(dbobj, propname, value)
elif FULL_PERSISTENCE:
dbobj.set_attribute(propname, value)
else: else:
# not FULL_PERSISTENCE dbobj.set_attribute(propname, value)
ndb = object.__getattribute__(dbobj, 'ndb')
setattr(ndb, propname, value)
else: else:
object.__setattr__(self, propname, value) object.__setattr__(self, propname, value)
@ -187,7 +179,7 @@ class TypeClass(object):
def __delattr__(self, propname): def __delattr__(self, propname):
""" """
Transparently deletes data from the typeclass or dbobj by first searching on the typeclass, 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. Will not allow deletion of properties stored directly on dbobj.
""" """
try: try:
@ -210,13 +202,9 @@ class TypeClass(object):
logger.log_trace("This is probably due to an unsafe reload.") logger.log_trace("This is probably due to an unsafe reload.")
return # ignore delete return # ignore delete
try: try:
if FULL_PERSISTENCE: if not dbobj.has_attribute(propname):
if not dbobj.has_attribute(propname): raise AttributeError
raise AttributeError dbobj.del_attribute(propname)
dbobj.del_attribute(propname)
else:
ndb = object.__getattribute__(dbobj, 'ndb')
ndb.__delattr__(propname)
except AttributeError: except AttributeError:
string = "Object: '%s' not found on %s(%s), nor on its typeclass %s." string = "Object: '%s' not found on %s(%s), nor on its typeclass %s."
raise AttributeError(string % (propname, dbobj, raise AttributeError(string % (propname, dbobj,