Added caching to some more object properties.
This commit is contained in:
parent
bdf86b203d
commit
9660dd6656
3 changed files with 20 additions and 19 deletions
|
|
@ -346,7 +346,7 @@ start
|
||||||
#
|
#
|
||||||
@lock north = view:attr(last_climbed) ; traverse:attr(last_climbed)
|
@lock north = view:attr(last_climbed) ; traverse:attr(last_climbed)
|
||||||
#
|
#
|
||||||
@desc north
|
@desc north =
|
||||||
This is a hardly visible footpath leading off through the rain-beaten
|
This is a hardly visible footpath leading off through the rain-beaten
|
||||||
grass. It seems to circle the trees northward. You would never had
|
grass. It seems to circle the trees northward. You would never had
|
||||||
noticed it had you not seen it from above.
|
noticed it had you not seen it from above.
|
||||||
|
|
|
||||||
|
|
@ -242,29 +242,26 @@ class ObjectDB(TypedObject):
|
||||||
We have to be careful here since Player is also
|
We have to be careful here since Player is also
|
||||||
a TypedObject, so as to not create a loop.
|
a TypedObject, so as to not create a loop.
|
||||||
"""
|
"""
|
||||||
try:
|
return get_cache(self, "player")
|
||||||
return object.__getattribute__(self, 'db_player')
|
|
||||||
except AttributeError:
|
|
||||||
return None
|
|
||||||
#@player.setter
|
#@player.setter
|
||||||
def player_set(self, player):
|
def player_set(self, player):
|
||||||
"Setter. Allows for self.player = value"
|
"Setter. Allows for self.player = value"
|
||||||
if isinstance(player, TypeClass):
|
if isinstance(player, TypeClass):
|
||||||
player = player.dbobj
|
player = player.dbobj
|
||||||
self.db_player = player
|
set_cache(self, "player", player)
|
||||||
self.save()
|
|
||||||
#@player.deleter
|
#@player.deleter
|
||||||
def player_del(self):
|
def player_del(self):
|
||||||
"Deleter. Allows for del self.player"
|
"Deleter. Allows for del self.player"
|
||||||
self.db_player = None
|
self.db_player = None
|
||||||
self.save()
|
self.save()
|
||||||
|
del_cache(self, "player")
|
||||||
player = property(player_get, player_set, player_del)
|
player = property(player_get, player_set, player_del)
|
||||||
|
|
||||||
# location property (wraps db_location)
|
# location property (wraps db_location)
|
||||||
#@property
|
#@property
|
||||||
def location_get(self):
|
def location_get(self):
|
||||||
"Getter. Allows for value = self.location."
|
"Getter. Allows for value = self.location."
|
||||||
loc = self.db_location
|
loc = get_cache(self, "location")
|
||||||
if loc:
|
if loc:
|
||||||
return loc.typeclass
|
return loc.typeclass
|
||||||
return None
|
return None
|
||||||
|
|
@ -284,8 +281,7 @@ class ObjectDB(TypedObject):
|
||||||
loc = location.dbobj
|
loc = location.dbobj
|
||||||
else:
|
else:
|
||||||
loc = location.dbobj
|
loc = location.dbobj
|
||||||
self.db_location = loc
|
set_cache(self, "location", loc)
|
||||||
self.save()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
string = "Cannot set location: "
|
string = "Cannot set location: "
|
||||||
string += "%s is not a valid location."
|
string += "%s is not a valid location."
|
||||||
|
|
@ -297,13 +293,14 @@ class ObjectDB(TypedObject):
|
||||||
"Deleter. Allows for del self.location"
|
"Deleter. Allows for del self.location"
|
||||||
self.db_location = None
|
self.db_location = None
|
||||||
self.save()
|
self.save()
|
||||||
|
del_cache()
|
||||||
location = property(location_get, location_set, location_del)
|
location = property(location_get, location_set, location_del)
|
||||||
|
|
||||||
# home property (wraps db_home)
|
# home property (wraps db_home)
|
||||||
#@property
|
#@property
|
||||||
def home_get(self):
|
def home_get(self):
|
||||||
"Getter. Allows for value = self.home"
|
"Getter. Allows for value = self.home"
|
||||||
home = self.db_home
|
home = get_cache(self, "home")
|
||||||
if home:
|
if home:
|
||||||
return home.typeclass
|
return home.typeclass
|
||||||
return None
|
return None
|
||||||
|
|
@ -321,26 +318,26 @@ class ObjectDB(TypedObject):
|
||||||
hom = home.dbobj
|
hom = home.dbobj
|
||||||
else:
|
else:
|
||||||
hom = home.dbobj
|
hom = home.dbobj
|
||||||
self.db_home = hom
|
set_cache(self, "home", hom)
|
||||||
except Exception:
|
except Exception:
|
||||||
string = "Cannot set home: "
|
string = "Cannot set home: "
|
||||||
string += "%s is not a valid home."
|
string += "%s is not a valid home."
|
||||||
self.msg(string % home)
|
self.msg(string % home)
|
||||||
logger.log_trace(string)
|
logger.log_trace(string)
|
||||||
#raise
|
#raise
|
||||||
self.save()
|
|
||||||
#@home.deleter
|
#@home.deleter
|
||||||
def home_del(self):
|
def home_del(self):
|
||||||
"Deleter. Allows for del self.home."
|
"Deleter. Allows for del self.home."
|
||||||
self.db_home = None
|
self.db_home = None
|
||||||
self.save()
|
self.save()
|
||||||
|
del_cache(self, "home")
|
||||||
home = property(home_get, home_set, home_del)
|
home = property(home_get, home_set, home_del)
|
||||||
|
|
||||||
# destination property (wraps db_destination)
|
# destination property (wraps db_destination)
|
||||||
#@property
|
#@property
|
||||||
def destination_get(self):
|
def destination_get(self):
|
||||||
"Getter. Allows for value = self.destination."
|
"Getter. Allows for value = self.destination."
|
||||||
dest = self.db_destination
|
dest = get_cache(self, "destination")
|
||||||
if dest:
|
if dest:
|
||||||
return dest.typeclass
|
return dest.typeclass
|
||||||
return None
|
return None
|
||||||
|
|
@ -360,8 +357,7 @@ class ObjectDB(TypedObject):
|
||||||
dest = destination.dbobj
|
dest = destination.dbobj
|
||||||
else:
|
else:
|
||||||
dest = destination.dbobj
|
dest = destination.dbobj
|
||||||
self.db_destination = dest
|
set_cache(self, "destination", dest)
|
||||||
self.save()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
string = "Cannot set destination: "
|
string = "Cannot set destination: "
|
||||||
string += "%s is not a valid destination."
|
string += "%s is not a valid destination."
|
||||||
|
|
@ -373,9 +369,11 @@ class ObjectDB(TypedObject):
|
||||||
"Deleter. Allows for del self.destination"
|
"Deleter. Allows for del self.destination"
|
||||||
self.db_destination = None
|
self.db_destination = None
|
||||||
self.save()
|
self.save()
|
||||||
|
del_cache(self, "destination")
|
||||||
destination = property(destination_get, destination_set, destination_del)
|
destination = property(destination_get, destination_set, destination_del)
|
||||||
|
|
||||||
# cmdset_storage property
|
# cmdset_storage property.
|
||||||
|
# This seems very sensitive to caching, so leaving it be for now. /Griatch
|
||||||
#@property
|
#@property
|
||||||
def cmdset_storage_get(self):
|
def cmdset_storage_get(self):
|
||||||
"Getter. Allows for value = self.name. Returns a list of cmdset_storage."
|
"Getter. Allows for value = self.name. Returns a list of cmdset_storage."
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ def get_cache(obj, name):
|
||||||
return GA(obj, "_cached_db_%s" % name)
|
return GA(obj, "_cached_db_%s" % name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
val = GA(obj, "db_%s" % name)
|
val = GA(obj, "db_%s" % name)
|
||||||
SA(obj, "_cached_db_%s" % name, val)
|
if val: SA(obj, "_cached_db_%s" % name, val)
|
||||||
return val
|
return val
|
||||||
def set_cache(obj, name, val):
|
def set_cache(obj, name, val):
|
||||||
"On-model Cache setter"
|
"On-model Cache setter"
|
||||||
|
|
@ -68,7 +68,10 @@ def set_cache(obj, name, val):
|
||||||
|
|
||||||
def del_cache(obj, name):
|
def del_cache(obj, name):
|
||||||
"On-model cache deleter"
|
"On-model cache deleter"
|
||||||
|
try:
|
||||||
DA(obj, "_cached_db_%s" % name)
|
DA(obj, "_cached_db_%s" % name)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue