add server-timing
All checks were successful
Build and Publish / build_and_publish (push) Successful in 55s
All checks were successful
Build and Publish / build_and_publish (push) Successful in 55s
This commit is contained in:
parent
d7d1805622
commit
301e7b7417
1 changed files with 11 additions and 1 deletions
|
@ -105,18 +105,28 @@ def get_all_truths(
|
||||||
"""Retrieves all stored truths
|
"""Retrieves all stored truths
|
||||||
|
|
||||||
If ?limit is a positive integer, pagination will be enabled."""
|
If ?limit is a positive integer, pagination will be enabled."""
|
||||||
|
query_start = time.perf_counter()
|
||||||
keys = db.keys()
|
keys = db.keys()
|
||||||
|
query_end = time.perf_counter()
|
||||||
if rich is False:
|
if rich is False:
|
||||||
return [
|
return [
|
||||||
{"id": key, "content": "", "author": "", "timestamp": 0, "extra": None}
|
{"id": key, "content": "", "author": "", "timestamp": 0, "extra": None}
|
||||||
for key in keys
|
for key in keys
|
||||||
]
|
]
|
||||||
|
load_start = time.perf_counter()
|
||||||
truths = [json.loads(db.get(key)) for key in keys]
|
truths = [json.loads(db.get(key)) for key in keys]
|
||||||
|
load_end = time.perf_counter()
|
||||||
if limit >= 0:
|
if limit >= 0:
|
||||||
selection = truths[page * limit: (page + 1) * limit]
|
selection = truths[page * limit: (page + 1) * limit]
|
||||||
else:
|
else:
|
||||||
selection = truths
|
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])
|
@truth_router.get("/all", deprecated=True, response_model=list[TruthPayload])
|
||||||
|
|
Loading…
Reference in a new issue