mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 17:56:32 +01:00
Adding caching to tags and attribute lookups. Leads to a noticeable speed improvement.
This commit is contained in:
parent
6ad30a8ba5
commit
07af616b67
6 changed files with 145 additions and 150 deletions
41
src/utils/dummyrunner/test_queries.py
Normal file
41
src/utils/dummyrunner/test_queries.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""
|
||||
This is a little routine for viewing the sql queries that are executed by a given
|
||||
query as well as count them for optimization testing.
|
||||
|
||||
"""
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
os.environ["DJANGO_SETTINGS_MODULE"] = "game.settings"
|
||||
from django.db import connection
|
||||
|
||||
|
||||
def count_queries(exec_string, setup_string):
|
||||
"""
|
||||
Display queries done by exec_string. Use setup_string
|
||||
to setup the environment to test.
|
||||
"""
|
||||
|
||||
exec setup_string
|
||||
|
||||
num_queries_old = len(connection.queries)
|
||||
exec exec_string
|
||||
nqueries = len(connection.queries) - num_queries_old
|
||||
|
||||
for query in connection.queries[-nqueries if nqueries else 1:]:
|
||||
print query["time"], query["sql"]
|
||||
print "Number of queries: %s" % nqueries
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# setup tests here
|
||||
|
||||
setup_string = \
|
||||
"""
|
||||
from src.objects.models import ObjectDB
|
||||
g = ObjectDB.objects.get(db_key="Griatch")
|
||||
"""
|
||||
exec_string = \
|
||||
"""
|
||||
g.tags.all()
|
||||
"""
|
||||
count_queries(exec_string, setup_string)
|
||||
Loading…
Add table
Add a link
Reference in a new issue