Removing some of the last self-reference loops in object.models, based on profiling.

This commit is contained in:
Griatch 2012-09-20 02:52:21 +02:00
parent 4bd3be334d
commit 7a130cb442
2 changed files with 22 additions and 25 deletions

View file

@ -269,41 +269,38 @@ class ObjectDB(TypedObject):
"Getter. Allows for value = self.location." "Getter. Allows for value = self.location."
loc = _get_cache(self, "location") loc = _get_cache(self, "location")
if loc: if loc:
return loc.typeclass return _GA(loc, "typeclass")
return None return None
#@location.setter #@location.setter
def __location_set(self, location): def __location_set(self, location):
"Setter. Allows for self.location = location" "Setter. Allows for self.location = location"
try: try:
old_loc = _GA(self, "location") old_loc = _GA(_GA(self, "location"), "dbobj")
if location == None or type(location) == ObjectDB:
# location is None or a valid object if ObjectDB.objects.dbref(location):
loc = location # dbref search
elif ObjectDB.objects.dbref(location):
# location is a dbref; search
loc = ObjectDB.objects.dbref_search(location) loc = ObjectDB.objects.dbref_search(location)
if loc and hasattr(loc,'dbobj'): loc = loc and _GA(loc, "dbobj")
loc = loc.dbobj elif type(location) != ObjectDB:
loc = _GA(location, "dbobj")
else: else:
loc = location.dbobj loc = location
else:
loc = location.dbobj
_set_cache(self, "location", loc) _set_cache(self, "location", loc)
# update the contents of each location # update the contents of each location
if old_loc: if old_loc:
old_loc.contents_update(self, remove=True) _GA(old_loc, "contents_update")(self, remove=True)
if loc: if loc:
loc.contents_update(self.typeclass) _GA(loc, "contents_update")(_GA(self, "typeclass"))
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."
self.msg(_(string) % location) _GA(self, "msg")(_(string) % location)
logger.log_trace(string) logger.log_trace(string)
raise raise
#@location.deleter #@location.deleter
def __location_del(self): def __location_del(self):
"Deleter. Allows for del self.location" "Deleter. Allows for del self.location"
self.location.contents_update(self, remove=True) _GA(self, "location").contents_update(self, remove=True)
_SA(self, "db_location", None) _SA(self, "db_location", None)
_GA(self, "save")() _GA(self, "save")()
_del_cache(self, "location") _del_cache(self, "location")
@ -352,7 +349,7 @@ class ObjectDB(TypedObject):
"Getter. Allows for value = self.destination." "Getter. Allows for value = self.destination."
dest = _get_cache(self, "destination") dest = _get_cache(self, "destination")
if dest: if dest:
return dest.typeclass return _GA(dest, "typeclass")
return None return None
#@destination.setter #@destination.setter
def __destination_set(self, destination): def __destination_set(self, destination):
@ -364,24 +361,24 @@ class ObjectDB(TypedObject):
elif ObjectDB.objects.dbref(destination): elif ObjectDB.objects.dbref(destination):
# destination is a dbref; search # destination is a dbref; search
dest = ObjectDB.objects.dbref_search(destination) dest = ObjectDB.objects.dbref_search(destination)
if dest and hasattr(dest,'dbobj'): if dest and self._hasattr(dest,'dbobj'):
dest = dest.dbobj dest = _GA(dest, "dbobj")
else: else:
dest = destination.dbobj dest = _GA(destination, "dbobj")
else: else:
dest = destination.dbobj dest = destination.dbobj
_set_cache(self, "destination", dest) _set_cache(self, "destination", dest)
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."
self.msg(_(string) % destination) _GA(self, "msg")(_(string) % destination)
logger.log_trace(string) logger.log_trace(string)
raise raise
#@destination.deleter #@destination.deleter
def __destination_del(self): def __destination_del(self):
"Deleter. Allows for del self.destination" "Deleter. Allows for del self.destination"
self.db_destination = None _SA(self, "db_destination", None)
self.save() _GA(self, "save")()
_del_cache(self, "destination") _del_cache(self, "destination")
destination = property(__destination_get, __destination_set, __destination_del) destination = property(__destination_get, __destination_set, __destination_del)

View file

@ -101,12 +101,12 @@ DEFAULT_NCLIENTS = 1
# time between each 'tick', in seconds, if not set on command # time between each 'tick', in seconds, if not set on command
# line. All launched clients will be called upon to possibly do an # line. All launched clients will be called upon to possibly do an
# action with this frequency. # action with this frequency.
DEFAULT_TIMESTEP = 5 DEFAULT_TIMESTEP = 1#5
# Port to use, if not specified on command line # Port to use, if not specified on command line
DEFAULT_PORT = settings.TELNET_PORTS[0] DEFAULT_PORT = settings.TELNET_PORTS[0]
# chance of an action happening, per timestep. This helps to # chance of an action happening, per timestep. This helps to
# spread out usage randomly, like it would be in reality. # spread out usage randomly, like it would be in reality.
CHANCE_OF_ACTION = 0.1 CHANCE_OF_ACTION = 1#0.1
#------------------------------------------------------------ #------------------------------------------------------------