add server-timing
All checks were successful
Build and Publish / build_and_publish (push) Successful in 55s

This commit is contained in:
Nexus 2024-07-14 02:06:06 +01:00
parent d7d1805622
commit 301e7b7417
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -105,18 +105,28 @@ def get_all_truths(
"""Retrieves all stored truths
If ?limit is a positive integer, pagination will be enabled."""
query_start = time.perf_counter()
keys = db.keys()
query_end = time.perf_counter()
if rich is False:
return [
{"id": key, "content": "", "author": "", "timestamp": 0, "extra": None}
for key in keys
]
load_start = time.perf_counter()
truths = [json.loads(db.get(key)) for key in keys]
load_end = time.perf_counter()
if limit >= 0:
selection = truths[page * limit: (page + 1) * limit]
else:
selection = truths
return ORJSONResponse(selection)
whittle_end = time.perf_counter()
server_timing = "query;dur=%.2f, load;dur=%.2f, whittle;dur=%.2f" % (
(query_end - query_start) * 1000,
(load_end - load_start) * 1000,
(whittle_end - load_end) * 1000,
)
return ORJSONResponse(selection, headers={"Server-Timing": server_timing})
@truth_router.get("/all", deprecated=True, response_model=list[TruthPayload])