Switch to ujson and remove debugging statements

This commit is contained in:
Mark Veidemanis 2022-09-05 07:20:30 +01:00
parent 62455409e6
commit c2d78dc482
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import json
import ujson
import logging
import random
import string
@ -70,12 +70,11 @@ def construct_query(query, size, index, blank=False):
def run_query(client, user, search_query):
if settings.MANTICORE_CACHE:
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)
cache_hit = r.get(f"query_cache.{user.id}.{hash}")
if cache_hit:
print("Cache hit")
response = json.loads(cache_hit)
response = ujson.loads(cache_hit)
time_took = (time.process_time() - start) * 1000
# Round to 3 significant figures
time_took_rounded = round(
@ -90,11 +89,9 @@ def run_query(client, user, search_query):
# Write cache
if settings.MANTICORE_CACHE:
print("Writing to cache")
to_write_cache = json.dumps(response)
to_write_cache = ujson.dumps(response)
r.set(f"query_cache.{user.id}.{hash}", to_write_cache)
r.expire(f"query_cache.{user.id}.{hash}", settings.MANTICORE_CACHE_TIMEOUT)
print("Written to cache")
return response

View File

@ -1,4 +1,4 @@
import json
import ujson
import urllib
import uuid
@ -97,7 +97,7 @@ def make_graph(results):
"date": date,
}
)
return json.dumps(graph)
return ujson.dumps(graph)
def drilldown_search(request, return_context=False, template=None):

View File

@ -17,3 +17,4 @@ sortedcontainers
manticoresearch
django-debug-toolbar
django-debug-toolbar-template-profiler
ujson

View File

@ -16,3 +16,4 @@ sortedcontainers
manticoresearch
django-debug-toolbar
django-debug-toolbar-template-profiler
ujson

View File

@ -17,3 +17,4 @@ sortedcontainers
manticoresearch
django-debug-toolbar
django-debug-toolbar-template-profiler
ujson