mirror of
https://github.com/evennia/evennia.git
synced 2026-03-28 02:36:32 +01:00
Fixed a caching issue with TypedAttributes.
This commit is contained in:
parent
82a10903d1
commit
d4c97d7df8
3 changed files with 18 additions and 5 deletions
|
|
@ -119,8 +119,10 @@ class ObjectManager(TypedObjectManager):
|
|||
from src.objects.models import ObjAttribute
|
||||
lstring = ""
|
||||
if location:
|
||||
lstring = ", db_obj__db_location=location"
|
||||
lstring = ", db_obj__db_location=location"
|
||||
attrs = eval("ObjAttribute.objects.filter(db_key=attribute_name%s)" % lstring)
|
||||
# since attribute values are pickled in database, we cannot search directly, but
|
||||
# must loop through the results. .
|
||||
if exact:
|
||||
return [attr.obj for attr in attrs if attribute_value == attr.value]
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -81,6 +81,17 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
except Exception:
|
||||
return None
|
||||
return dbref
|
||||
|
||||
@returns_typeclass_list
|
||||
def get_with_attr(self, attribute_name, attribute_value=None):
|
||||
"""
|
||||
Returns the typeclassed entity depending on having a given attribute.
|
||||
|
||||
attribute_name - only entities with an attribute of this name will be included in match
|
||||
attribute_value - if != None, only entities with db.attribute_name=attribute_value will match.
|
||||
"""
|
||||
self.filter()
|
||||
|
||||
|
||||
@returns_typeclass
|
||||
def dbref_search(self, dbref):
|
||||
|
|
|
|||
|
|
@ -307,24 +307,24 @@ class Attribute(SharedMemoryModel):
|
|||
#@property
|
||||
def obj_get(self):
|
||||
"Getter. Allows for value = self.obj"
|
||||
return get_cache(self, "db_obj")
|
||||
return get_cache(self, "obj")
|
||||
#@obj.setter
|
||||
def obj_set(self, value):
|
||||
"Setter. Allows for self.obj = value"
|
||||
set_cache(self, "db_obj", value)
|
||||
set_cache(self, "obj", value)
|
||||
#@obj.deleter
|
||||
def obj_del(self):
|
||||
"Deleter. Allows for del self.obj"
|
||||
self.db_obj = None
|
||||
self.save()
|
||||
del_cache(self, "db_obj")
|
||||
del_cache(self, "obj")
|
||||
obj = property(obj_get, obj_set, obj_del)
|
||||
|
||||
# date_created property (wraps db_date_created)
|
||||
#@property
|
||||
def date_created_get(self):
|
||||
"Getter. Allows for value = self.date_created"
|
||||
return get_cache(self, "db_date_created")
|
||||
return get_cache(self, "date_created")
|
||||
#@date_created.setter
|
||||
def date_created_set(self, value):
|
||||
"Setter. Allows for self.date_created = value"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue