Some optimizations towards speeding up getting the contents of a location.

This commit is contained in:
Griatch 2012-08-19 11:45:13 +02:00
parent 1dee271fc7
commit cc88d38ab6
2 changed files with 10 additions and 9 deletions

View file

@ -7,7 +7,7 @@ from django.db.models.fields import exceptions
from src.typeclasses.managers import TypedObjectManager from src.typeclasses.managers import TypedObjectManager
from src.typeclasses.managers import returns_typeclass, returns_typeclass_list from src.typeclasses.managers import returns_typeclass, returns_typeclass_list
from src.utils import utils from src.utils import utils
from src.utils.utils import to_unicode from src.utils.utils import to_unicode, make_iter
ObjAttribute = None ObjAttribute = None
@ -194,11 +194,13 @@ class ObjectManager(TypedObjectManager):
""" """
Get all objects that has a location Get all objects that has a location
set to this one. set to this one.
excludeobjs - one or more object keys to exclude from the match
""" """
estring = "" query = self.filter(db_location__id=location.id, )
if excludeobj: for objkey in make_iter(excludeobj):
estring = ".exclude(db_key=excludeobj)" query = query.exclude(db_key=objkey)
return eval("self.filter(db_location__id=location.id)%s" % estring) return query
@returns_typeclass_list @returns_typeclass_list
def object_search(self, ostring, caller=None, def object_search(self, ostring, caller=None,

View file

@ -885,10 +885,9 @@ class TypedObject(SharedMemoryModel):
# typeclass' __getattribute__, since that one would # typeclass' __getattribute__, since that one would
# try to look back to this very database object.) # try to look back to this very database object.)
typeclass = _GA(self, 'typeclass') typeclass = _GA(self, 'typeclass')
if typeclass: # will raise AttributeError also if typeclass was malformed
return _GA(typeclass, propname) return _GA(typeclass, propname)
else:
raise AttributeError
#@property #@property
_dbid_cache = None _dbid_cache = None
def __dbid_get(self): def __dbid_get(self):