From cc88d38ab67f839bc70dac7a0a6cf4c0b3186bc1 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 19 Aug 2012 11:45:13 +0200 Subject: [PATCH] Some optimizations towards speeding up getting the contents of a location. --- src/objects/manager.py | 12 +++++++----- src/typeclasses/models.py | 7 +++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/objects/manager.py b/src/objects/manager.py index b1645ce4bf..77d112cb27 100644 --- a/src/objects/manager.py +++ b/src/objects/manager.py @@ -7,7 +7,7 @@ from django.db.models.fields import exceptions from src.typeclasses.managers import TypedObjectManager from src.typeclasses.managers import returns_typeclass, returns_typeclass_list from src.utils import utils -from src.utils.utils import to_unicode +from src.utils.utils import to_unicode, make_iter ObjAttribute = None @@ -194,11 +194,13 @@ class ObjectManager(TypedObjectManager): """ Get all objects that has a location set to this one. + + excludeobjs - one or more object keys to exclude from the match """ - estring = "" - if excludeobj: - estring = ".exclude(db_key=excludeobj)" - return eval("self.filter(db_location__id=location.id)%s" % estring) + query = self.filter(db_location__id=location.id, ) + for objkey in make_iter(excludeobj): + query = query.exclude(db_key=objkey) + return query @returns_typeclass_list def object_search(self, ostring, caller=None, diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index f79839e39c..cec9ea4668 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -885,10 +885,9 @@ class TypedObject(SharedMemoryModel): # typeclass' __getattribute__, since that one would # try to look back to this very database object.) typeclass = _GA(self, 'typeclass') - if typeclass: - return _GA(typeclass, propname) - else: - raise AttributeError + # will raise AttributeError also if typeclass was malformed + return _GA(typeclass, propname) + #@property _dbid_cache = None def __dbid_get(self):