diff --git a/src/server.py b/src/server.py index f5480e3..5b39ccf 100644 --- a/src/server.py +++ b/src/server.py @@ -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])