From c49621314e437be6ea550c76e0811e62d73f28fb Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 27 Dec 2021 19:39:50 +0100 Subject: [PATCH] feat(api): search by TTFB --- api/chalicelib/core/performance_event.py | 1 + api/chalicelib/core/sessions.py | 6 ++++-- api/schemas.py | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/chalicelib/core/performance_event.py b/api/chalicelib/core/performance_event.py index d8cb2da6b..194ab1895 100644 --- a/api/chalicelib/core/performance_event.py +++ b/api/chalicelib/core/performance_event.py @@ -4,5 +4,6 @@ import schemas def get_col(perf: schemas.PerformanceEventType): return { schemas.PerformanceEventType.location_dom_complete: "dom_building_time", + schemas.PerformanceEventType.ttfb: "ttfb", # schemas.PerformanceEventType.location_largest_contentful_paint_time: "timestamp" }.get(perf) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 509607ddc..cf8e93c1d 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -440,8 +440,9 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f event_where.append( _multiple_conditions(f"(main1.reason {op} %({e_k})s OR main1.name {op} %({e_k})s)", event.value, value_key=e_k)) - elif event_type == [schemas.PerformanceEventType.location_dom_complete, - schemas.PerformanceEventType.location_largest_contentful_paint_time]: + elif event_type in [schemas.PerformanceEventType.location_dom_complete, + schemas.PerformanceEventType.location_largest_contentful_paint_time, + schemas.PerformanceEventType.ttfb]: event_from = event_from % f"{events.event_type.LOCATION.table} AS main " if not is_any: event_where.append( @@ -488,6 +489,7 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f else: + print("LLLLLLLLLLLLLL") continue if event_index == 0 or or_events: event_where += ss_constraints diff --git a/api/schemas.py b/api/schemas.py index 8c31b1772..72eb4f65b 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -372,6 +372,7 @@ class PerformanceEventType(str, Enum): location_dom_complete = "DOM_COMPLETE" location_largest_contentful_paint_time = "LARGEST_CONTENTFUL_PAINT_TIME" time_between_events = "TIME_BETWEEN_EVENTS" + ttfb = "TTFB" class FilterType(str, Enum): @@ -459,6 +460,9 @@ class _SessionSearchEventRaw(BaseModel): assert isinstance(values["value"][0], _SessionSearchEventRaw) \ and isinstance(values["value"][1], _SessionSearchEventRaw) \ , f"event should be of type _SessionSearchEventRaw for {PerformanceEventType.time_between_events}" + else: + for c in values["custom"]: + assert isinstance(c, int), f"custom value should be of type int for {values.get('type')}" return values