Switch to ujson and remove debugging statements
This commit is contained in:
parent
62455409e6
commit
c2d78dc482
|
@ -1,4 +1,4 @@
|
||||||
import json
|
import ujson
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
@ -70,12 +70,11 @@ def construct_query(query, size, index, blank=False):
|
||||||
def run_query(client, user, search_query):
|
def run_query(client, user, search_query):
|
||||||
if settings.MANTICORE_CACHE:
|
if settings.MANTICORE_CACHE:
|
||||||
start = time.process_time()
|
start = time.process_time()
|
||||||
query_normalised = json.dumps(search_query, sort_keys=True)
|
query_normalised = ujson.dumps(search_query, sort_keys=True)
|
||||||
hash = siphash(hash_key, query_normalised)
|
hash = siphash(hash_key, query_normalised)
|
||||||
cache_hit = r.get(f"query_cache.{user.id}.{hash}")
|
cache_hit = r.get(f"query_cache.{user.id}.{hash}")
|
||||||
if cache_hit:
|
if cache_hit:
|
||||||
print("Cache hit")
|
response = ujson.loads(cache_hit)
|
||||||
response = json.loads(cache_hit)
|
|
||||||
time_took = (time.process_time() - start) * 1000
|
time_took = (time.process_time() - start) * 1000
|
||||||
# Round to 3 significant figures
|
# Round to 3 significant figures
|
||||||
time_took_rounded = round(
|
time_took_rounded = round(
|
||||||
|
@ -90,11 +89,9 @@ def run_query(client, user, search_query):
|
||||||
|
|
||||||
# Write cache
|
# Write cache
|
||||||
if settings.MANTICORE_CACHE:
|
if settings.MANTICORE_CACHE:
|
||||||
print("Writing to cache")
|
to_write_cache = ujson.dumps(response)
|
||||||
to_write_cache = json.dumps(response)
|
|
||||||
r.set(f"query_cache.{user.id}.{hash}", to_write_cache)
|
r.set(f"query_cache.{user.id}.{hash}", to_write_cache)
|
||||||
r.expire(f"query_cache.{user.id}.{hash}", settings.MANTICORE_CACHE_TIMEOUT)
|
r.expire(f"query_cache.{user.id}.{hash}", settings.MANTICORE_CACHE_TIMEOUT)
|
||||||
print("Written to cache")
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json
|
import ujson
|
||||||
import urllib
|
import urllib
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ def make_graph(results):
|
||||||
"date": date,
|
"date": date,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return json.dumps(graph)
|
return ujson.dumps(graph)
|
||||||
|
|
||||||
|
|
||||||
def drilldown_search(request, return_context=False, template=None):
|
def drilldown_search(request, return_context=False, template=None):
|
||||||
|
|
|
@ -17,3 +17,4 @@ sortedcontainers
|
||||||
manticoresearch
|
manticoresearch
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
django-debug-toolbar-template-profiler
|
django-debug-toolbar-template-profiler
|
||||||
|
ujson
|
||||||
|
|
|
@ -16,3 +16,4 @@ sortedcontainers
|
||||||
manticoresearch
|
manticoresearch
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
django-debug-toolbar-template-profiler
|
django-debug-toolbar-template-profiler
|
||||||
|
ujson
|
||||||
|
|
|
@ -17,3 +17,4 @@ sortedcontainers
|
||||||
manticoresearch
|
manticoresearch
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
django-debug-toolbar-template-profiler
|
django-debug-toolbar-template-profiler
|
||||||
|
ujson
|
||||||
|
|
Loading…
Reference in New Issue