Fix annotating results and remove debugging code

Mark Veidemanis 2 years ago
parent c49c8898eb
commit 1bdd332e6e
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -267,8 +267,6 @@ class StorageBackend(ABC):
cache_hit = r.get(f"query_cache.{user.id}.{hash}")
if cache_hit:
response = orjson.loads(cache_hit)
print("CACHE HIT", response)
time_took = (time.process_time() - start) * 1000
# Round to 3 significant figures
time_took_rounded = round(
@ -301,8 +299,6 @@ class StorageBackend(ABC):
return context
else:
return response
# response = response.to_dict()
# print("RESP", response)
if "took" in response:
if response["took"] is None:
return None
@ -331,7 +327,7 @@ class StorageBackend(ABC):
def process_results(self, response, **kwargs):
if kwargs.get("annotate"):
annotate_results(response)
if kwargs.get("dedup"):
if kwargs.get("reverse"):
response = response[::-1]
if kwargs.get("dedup"):
if not kwargs.get("dedup_fields"):

@ -234,11 +234,6 @@ class DruidBackend(StorageBackend):
dedup_fields=dedup_fields,
reverse=reverse,
)
# ss = orjson.dumps(list(response), option=orjson.OPT_INDENT_2)
# ss = ss.decode()
# print(ss)
# print("PARSED", results_parsed)
# return results_parsed
context = response
return context

@ -37,7 +37,7 @@ class ElasticsearchBackend(StorageBackend):
extra_should = []
extra_should2 = []
if num:
extra_must.append({"equals": {"num": num}})
extra_must.append({"match_phrase": {"num": num}})
if net:
extra_must.append({"match_phrase": {"net": net}})
if channel:
@ -321,10 +321,12 @@ class ElasticsearchBackend(StorageBackend):
search_query,
index=index,
)
if "message" in response:
return response
# A/D/R - Annotate/Dedup/Reverse
self.process_results(
response,
response["object_list"],
annotate=annotate,
dedup=dedup,
dedup_fields=dedup_fields,

@ -3,7 +3,7 @@ from datetime import datetime
from core.lib.threshold import annotate_num_chans, annotate_num_users, annotate_online
def annotate_results(results_parsed):
def annotate_results(results):
"""
Accept a list of dict objects, search for the number of channels and users.
Add them to the object.
@ -11,7 +11,7 @@ def annotate_results(results_parsed):
"""
# Figure out items with net (not discord)
nets = set()
for x in results_parsed["object_list"]:
for x in results:
if "net" in x:
nets.add(x["net"])
@ -21,7 +21,7 @@ def annotate_results(results_parsed):
set(
[
x["nick"]
for x in results_parsed["object_list"]
for x in results
if {"nick", "src", "net"}.issubset(x)
and x["src"] == "irc"
and x["net"] == net
@ -32,7 +32,7 @@ def annotate_results(results_parsed):
set(
[
x["channel"]
for x in results_parsed["object_list"]
for x in results
if {"channel", "src", "net"}.issubset(x)
and x["src"] == "irc"
and x["net"] == net
@ -44,7 +44,7 @@ def annotate_results(results_parsed):
num_users = annotate_num_users(net, channels)
# Annotate the number channels the user is on
num_chans = annotate_num_chans(net, nicks)
for item in results_parsed["object_list"]:
for item in results:
if "net" in item:
if item["net"] == net:
if "nick" in item:

Loading…
Cancel
Save