Added cmdset caching to cmdhandler.
This commit is contained in:
parent
a00179b742
commit
efa6d85574
2 changed files with 34 additions and 27 deletions
|
|
@ -47,8 +47,8 @@ from src.utils.utils import string_suggestions, make_iter
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
__all__ = ("cmdhandler",)
|
__all__ = ("cmdhandler",)
|
||||||
|
|
||||||
_GA = object.__getattribute__
|
_GA = object.__getattribute__
|
||||||
|
_CMDSET_MERGE_CACHE = {}
|
||||||
|
|
||||||
# This decides which command parser is to be used.
|
# This decides which command parser is to be used.
|
||||||
# You have to restart the server for changes to take effect.
|
# You have to restart the server for changes to take effect.
|
||||||
|
|
@ -193,26 +193,32 @@ def get_and_merge_cmdsets(caller, session, player, obj, callertype, sessid=None)
|
||||||
yield [report_to.msg(cmdset.errmessage) for cmdset in cmdsets if cmdset.key == "_CMDSET_ERROR"]
|
yield [report_to.msg(cmdset.errmessage) for cmdset in cmdsets if cmdset.key == "_CMDSET_ERROR"]
|
||||||
|
|
||||||
if cmdsets:
|
if cmdsets:
|
||||||
# we group and merge all same-prio cmdsets separately (this avoids order-dependent
|
mergehash = tuple([id(cmdset) for cmdset in cmdsets]) # faster to do tuple on list than to build tuple directly
|
||||||
# clashes in certain cases, such as when duplicates=True)
|
if mergehash in _CMDSET_MERGE_CACHE:
|
||||||
tempmergers = {}
|
# cached merge exist; use that
|
||||||
for cmdset in cmdsets:
|
cmdset = _CMDSET_MERGE_CACHE[mergehash]
|
||||||
prio = cmdset.priority
|
else:
|
||||||
if prio in tempmergers:
|
# we group and merge all same-prio cmdsets separately (this avoids order-dependent
|
||||||
# merge same-prio cmdset together separately
|
# clashes in certain cases, such as when duplicates=True)
|
||||||
tempmergers[prio] = yield cmdset + tempmergers[prio]
|
tempmergers = {}
|
||||||
else:
|
for cmdset in cmdsets:
|
||||||
tempmergers[prio] = cmdset
|
prio = cmdset.priority
|
||||||
|
if prio in tempmergers:
|
||||||
|
# merge same-prio cmdset together separately
|
||||||
|
tempmergers[prio] = yield cmdset + tempmergers[prio]
|
||||||
|
else:
|
||||||
|
tempmergers[prio] = cmdset
|
||||||
|
|
||||||
# sort cmdsets after reverse priority (highest prio are merged in last)
|
# sort cmdsets after reverse priority (highest prio are merged in last)
|
||||||
cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority)
|
cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority)
|
||||||
|
|
||||||
# Merge all command sets into one, beginning with the lowest-prio one
|
# Merge all command sets into one, beginning with the lowest-prio one
|
||||||
cmdset = cmdsets.pop(0)
|
cmdset = cmdsets.pop(0)
|
||||||
for merging_cmdset in cmdsets:
|
for merging_cmdset in cmdsets:
|
||||||
#print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype,
|
#print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype,
|
||||||
# cmdset.key, cmdset.priority, cmdset.mergetype)
|
# cmdset.key, cmdset.priority, cmdset.mergetype)
|
||||||
cmdset = yield merging_cmdset + cmdset
|
cmdset = yield merging_cmdset + cmdset
|
||||||
|
_CMDSET_MERGE_CACHE[mergehash] = cmdset
|
||||||
else:
|
else:
|
||||||
cmdset = None
|
cmdset = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,15 @@ from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
# Tack on the root evennia directory to the python path and initialize django settings
|
# Tack on the root evennia directory to the python path and initialize django settings
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||||
from game import settings
|
os.environ["DJANGO_SETTINGS_MODULE"] = "game.settings"
|
||||||
try:
|
#from game import settings
|
||||||
from django.conf import settings as settings2
|
#try:
|
||||||
settings2.configure()
|
# from django.conf import settings as settings2
|
||||||
except RuntimeError
|
# settings2.configure()
|
||||||
pass
|
#except RuntimeError:
|
||||||
finally:
|
# pass
|
||||||
del settings2
|
#finally:
|
||||||
|
# del settings2
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.utils import utils
|
from src.utils import utils
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue