Removed caching of Attribute values, since this caused problems when storing and deleting database objects. There is an overhead from unpickling every call; hopefully not too bad (and if it is, one needs to use strvalue storage instead).

This commit is contained in:
Griatch 2013-11-12 19:32:24 +01:00
parent 2e2c2fd484
commit 8f914196f4
2 changed files with 26 additions and 11 deletions

View file

@ -2,6 +2,10 @@
Contribution - Griatch 2011 Contribution - Griatch 2011
[Note - with the advent of MULTISESSION_MODE=2, this is not really
as necessary anymore - the ooclook and @charcreate commands in that
mode replaces this module with better functionality.]
This is a simple character creation commandset. A suggestion is to This is a simple character creation commandset. A suggestion is to
test this together with menu_login, which doesn't create a Character test this together with menu_login, which doesn't create a Character
on its own. This shows some more info and gives the Player the option on its own. This shows some more info and gives the Player the option

View file

@ -135,28 +135,39 @@ class Attribute(SharedMemoryModel):
#@property #@property
def __value_get(self): def __value_get(self):
""" """
Getter. Allows for value = self.value. Reads from cache if possible. Getter. Allows for value = self.value.
We cannot cache here since it makes certain cases (such
as storing a dbobj which is then deleted elswhere) out-of-sync.
The overhead of unpickling seems hard to avoid.
""" """
if self.no_cache: return from_pickle(self.db_value, db_obj=self)
# re-create data from database and cache it #if self.no_cache:
value = from_pickle(self.db_value, db_obj=self) # # re-create data from database and cache it
self.cached_value = value # value = from_pickle(self.db_value, db_obj=self)
self.no_cache = False # self.cached_value = value
return self.cached_value # self.no_cache = False
#return self.cached_value
#@value.setter #@value.setter
def __value_set(self, new_value): def __value_set(self, new_value):
""" """
Setter. Allows for self.value = value. We make sure to cache everything. Setter. Allows for self.value = value. We make sure to cache everything.
""" """
to_store = to_pickle(new_value) self.db_value = to_pickle(new_value)
self.cached_value = from_pickle(to_store, db_obj=self)
self.no_cache = False
self.db_value = to_store
self.save() self.save()
try: try:
self._track_db_value_change.update(self.cached_value) self._track_db_value_change.update(self.cached_value)
except AttributeError: except AttributeError:
pass pass
return
#to_store = to_pickle(new_value)
#self.cached_value = from_pickle(to_store, db_obj=self)
#self.no_cache = False
#self.db_value = to_store
#self.save()
#try:
# self._track_db_value_change.update(self.cached_value)
#except AttributeError:
# pass
#@value.deleter #@value.deleter
def __value_del(self): def __value_del(self):
"Deleter. Allows for del attr.value. This removes the entire attribute." "Deleter. Allows for del attr.value. This removes the entire attribute."