Changed how tags are looked up during their creation, makes for a much faster implementation.
This commit is contained in:
parent
6816e200b6
commit
6bbd35da8a
1 changed files with 28 additions and 10 deletions
|
|
@ -97,21 +97,38 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
|
|
||||||
# Tag manager methods
|
# Tag manager methods
|
||||||
|
|
||||||
def get_tag(self, key=None, category=None, obj=None, tagtype=None):
|
def get_tag(self, key=None, category=None, obj=None, tagtype=None, global_search=False):
|
||||||
"""
|
"""
|
||||||
Return Tag objects by key, by category, by object (it is
|
Return Tag objects by key, by category, by object (it is
|
||||||
stored on) or with a combination of those criteria.
|
stored on) or with a combination of those criteria.
|
||||||
|
|
||||||
tagtype - one of None (normal tags), "alias" or "permission"
|
tagtype - one of None (normal tags), "alias" or "permission"
|
||||||
|
global_search - include all possible tags, not just tags on
|
||||||
|
this object
|
||||||
"""
|
"""
|
||||||
query = [("tag__db_tagtype", tagtype)]
|
global _Tag
|
||||||
if obj:
|
if not _Tag:
|
||||||
query.append(("%s__id" % self.model.__name__.lower(), obj.id))
|
from evennia.typeclasses.models import Tag as _Tag
|
||||||
if key:
|
if global_search:
|
||||||
query.append(("tag__db_key", key))
|
# search all tags using the Tag model
|
||||||
if category:
|
query = [("db_tagtype", tagtype)]
|
||||||
query.append(("tag__db_category", category))
|
if obj:
|
||||||
return [th.tag for th in self.model.db_tags.through.objects.filter(**dict(query))]
|
query.append(("id", obj.id))
|
||||||
|
if key:
|
||||||
|
query.append(("db_key", key))
|
||||||
|
if category:
|
||||||
|
query.append(("db_category", category))
|
||||||
|
return _Tag.objects.filter(**dict(query))
|
||||||
|
else:
|
||||||
|
# search only among tags stored on on this model
|
||||||
|
query = [("tag__db_tagtype", tagtype)]
|
||||||
|
if obj:
|
||||||
|
query.append(("%s__id" % self.model.__name__.lower(), obj.id))
|
||||||
|
if key:
|
||||||
|
query.append(("tag__db_key", key))
|
||||||
|
if category:
|
||||||
|
query.append(("tag__db_category", category))
|
||||||
|
return [th.tag for th in self.model.db_tags.through.objects.filter(**dict(query))]
|
||||||
|
|
||||||
def get_permission(self, key=None, category=None, obj=None):
|
def get_permission(self, key=None, category=None, obj=None):
|
||||||
return self.get_tag(key=key, category=category, obj=obj, tagtype="permission")
|
return self.get_tag(key=key, category=category, obj=obj, tagtype="permission")
|
||||||
|
|
@ -151,7 +168,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
"""
|
"""
|
||||||
data = str(data) if data is not None else None
|
data = str(data) if data is not None else None
|
||||||
# try to get old tag
|
# try to get old tag
|
||||||
tag = self.get_tag(key=key, category=category, tagtype=tagtype)
|
|
||||||
|
tag = self.get_tag(key=key, category=category, tagtype=tagtype, global_search=True)
|
||||||
if tag and data is not None:
|
if tag and data is not None:
|
||||||
# overload data on tag
|
# overload data on tag
|
||||||
tag.db_data = data
|
tag.db_data = data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue