From c2d78dc482eec50e7abd296bf07b2a7f8ad7c8ab Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 5 Sep 2022 07:20:30 +0100 Subject: [PATCH] Switch to ujson and remove debugging statements --- core/lib/manticore.py | 11 ++++------- core/views/ui/drilldown.py | 4 ++-- docker/prod/requirements.prod.txt | 1 + docker/requirements.dev.txt | 1 + requirements.txt | 1 + 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/lib/manticore.py b/core/lib/manticore.py index 7e403d1..4cc379c 100644 --- a/core/lib/manticore.py +++ b/core/lib/manticore.py @@ -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 diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index 8e293d2..bd7b0f6 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -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): diff --git a/docker/prod/requirements.prod.txt b/docker/prod/requirements.prod.txt index 6a1fa48..5207f36 100644 --- a/docker/prod/requirements.prod.txt +++ b/docker/prod/requirements.prod.txt @@ -17,3 +17,4 @@ sortedcontainers manticoresearch django-debug-toolbar django-debug-toolbar-template-profiler +ujson diff --git a/docker/requirements.dev.txt b/docker/requirements.dev.txt index cac00a9..473f04e 100644 --- a/docker/requirements.dev.txt +++ b/docker/requirements.dev.txt @@ -16,3 +16,4 @@ sortedcontainers manticoresearch django-debug-toolbar django-debug-toolbar-template-profiler +ujson diff --git a/requirements.txt b/requirements.txt index 18b09ab..1dfeda1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,4 @@ sortedcontainers manticoresearch django-debug-toolbar django-debug-toolbar-template-profiler +ujson