From 0a1bcd36c2bb2678b7b0615a7a8810911e16ece7 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 1 Oct 2011 15:10:21 +0200 Subject: [PATCH] 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. --- src/objects/models.py | 1 - src/settings_default.py | 11 ----------- src/typeclasses/models.py | 14 +++++--------- src/typeclasses/typeclass.py | 26 +++++++------------------- 4 files changed, 12 insertions(+), 40 deletions(-) diff --git a/src/objects/models.py b/src/objects/models.py index 367822f5f0..5ce79fbd66 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -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)) #------------------------------------------------------------ diff --git a/src/settings_default.py b/src/settings_default.py index 8f4d79eefb..64f747a651 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -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. diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 494d871e50..93c9e609ab 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -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 diff --git a/src/typeclasses/typeclass.py b/src/typeclasses/typeclass.py index 83155db91d..4a7352ad82 100644 --- a/src/typeclasses/typeclass.py +++ b/src/typeclasses/typeclass.py @@ -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,