From fc396d792a57bcce738cf4ef370030c1c341d7d6 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 25 Jan 2022 17:07:39 +0100 Subject: [PATCH] feat(api): sessions search use source and sourceOperator instead of custom and customOperator feat(api): sessions search remove custom, customOperator, key --- api/chalicelib/core/sessions.py | 30 +++++++++++++++--------------- api/schemas.py | 20 +++++++------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 113c2c754..5f7cd23af 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -488,10 +488,10 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr event_where.append( _multiple_conditions(f"main.{events.event_type.INPUT.column} {op} %({e_k})s", event.value, value_key=e_k)) - if event.custom is not None and len(event.custom) > 0: - event_where.append(_multiple_conditions(f"main.value ILIKE %(custom{i})s", event.custom, + if event.source is not None and len(event.source) > 0: + event_where.append(_multiple_conditions(f"main.value ILIKE %(custom{i})s", event.source, value_key=f"custom{i}")) - full_args = {**full_args, **_multiple_values(event.custom, value_key=f"custom{i}")} + full_args = {**full_args, **_multiple_values(event.source, value_key=f"custom{i}")} elif event_type == events.event_type.LOCATION.ui_type: event_from = event_from % f"{events.event_type.LOCATION.table} AS main " @@ -551,10 +551,10 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr event_where.append( _multiple_conditions(f"main.{events.event_type.INPUT_IOS.column} {op} %({e_k})s", event.value, value_key=e_k)) - if event.custom is not None and len(event.custom) > 0: - event_where.append(_multiple_conditions(f"main.value ILIKE %(custom{i})s", event.custom, + if event.source is not None and len(event.source) > 0: + event_where.append(_multiple_conditions(f"main.value ILIKE %(custom{i})s", event.source, value_key="custom{i}")) - full_args = {**full_args, **_multiple_values(event.custom, f"custom{i}")} + full_args = {**full_args, **_multiple_values(event.source, f"custom{i}")} elif event_type == events.event_type.VIEW_IOS.ui_type: event_from = event_from % f"{events.event_type.VIEW_IOS.table} AS main " if not is_any: @@ -598,10 +598,10 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr # colname = col["column"] # tname = "main" # e_k += "_custom" - # full_args = {**full_args, **_multiple_values(event.custom, value_key=e_k)} + # full_args = {**full_args, **_multiple_values(event.source, value_key=e_k)} # event_where.append(f"{tname}.{colname} IS NOT NULL AND {tname}.{colname}>0 AND " + - # _multiple_conditions(f"{tname}.{colname} {event.customOperator} %({e_k})s", - # event.custom, value_key=e_k)) + # _multiple_conditions(f"{tname}.{colname} {event.sourceOperator} %({e_k})s", + # event.source, value_key=e_k)) elif event_type in [schemas.PerformanceEventType.location_dom_complete, schemas.PerformanceEventType.location_largest_contentful_paint_time, schemas.PerformanceEventType.location_ttfb, @@ -622,11 +622,11 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr _multiple_conditions(f"main.{events.event_type.LOCATION.column} {op} %({e_k})s", event.value, value_key=e_k)) e_k += "_custom" - full_args = {**full_args, **_multiple_values(event.custom, value_key=e_k)} + full_args = {**full_args, **_multiple_values(event.source, value_key=e_k)} event_where.append(f"{tname}.{colname} IS NOT NULL AND {tname}.{colname}>0 AND " + - _multiple_conditions(f"{tname}.{colname} {event.customOperator} %({e_k})s", - event.custom, value_key=e_k)) + _multiple_conditions(f"{tname}.{colname} {event.sourceOperator} %({e_k})s", + event.source, value_key=e_k)) elif event_type == schemas.PerformanceEventType.time_between_events: event_from = event_from % f"{getattr(events.event_type, event.value[0].type).table} AS main INNER JOIN {getattr(events.event_type, event.value[1].type).table} AS main2 USING(session_id) " if not isinstance(event.value[0].value, list): @@ -657,10 +657,10 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr event.value[1].value, value_key=e_k2)) e_k += "_custom" - full_args = {**full_args, **_multiple_values(event.custom, value_key=e_k)} + full_args = {**full_args, **_multiple_values(event.source, value_key=e_k)} event_where.append( - _multiple_conditions(f"main2.timestamp - main.timestamp {event.customOperator} %({e_k})s", - event.custom, value_key=e_k)) + _multiple_conditions(f"main2.timestamp - main.timestamp {event.sourceOperator} %({e_k})s", + event.source, value_key=e_k)) else: diff --git a/api/schemas.py b/api/schemas.py index a09178df9..11d882e79 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -467,22 +467,20 @@ class __MixedSearchFilter(BaseModel): class _SessionSearchEventRaw(__MixedSearchFilter): is_event: bool = Field(True, const=True) - custom: Optional[List[Union[int, str]]] = Field(None, min_items=1) - customOperator: Optional[MathOperator] = Field(None) - key: Optional[str] = Field(None) value: Union[str, List[str]] = Field(...) type: Union[EventType, PerformanceEventType] = Field(...) operator: SearchEventOperator = Field(...) - source: Optional[ErrorSource] = Field(default=ErrorSource.js_exception) + source: Optional[Union[ErrorSource,List[Union[int, str]]]] = Field(default=ErrorSource.js_exception) + sourceOperator: Optional[MathOperator] = Field(None) @root_validator def event_validator(cls, values): if isinstance(values.get("type"), PerformanceEventType): if values.get("type") == PerformanceEventType.fetch_failed: return values - assert values.get("custom") is not None, "custom should not be null for PerformanceEventType" - assert values.get("customOperator") is not None \ - , "customOperator should not be null for PerformanceEventType" + assert values.get("source") is not None, "source should not be null for PerformanceEventType" + assert values.get("sourceOperator") is not None \ + , "sourceOperator should not be null for PerformanceEventType" if values["type"] == PerformanceEventType.time_between_events: assert len(values.get("value", [])) == 2, \ f"must provide 2 Events as value for {PerformanceEventType.time_between_events}" @@ -490,8 +488,8 @@ class _SessionSearchEventRaw(__MixedSearchFilter): 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')}" + for c in values["source"]: + assert isinstance(c, int), f"source value should be of type int for {values.get('type')}" return values @@ -501,7 +499,6 @@ class _SessionSearchEventSchema(_SessionSearchEventRaw): class _SessionSearchFilterSchema(__MixedSearchFilter): is_event: bool = Field(False, const=False) - custom: Optional[List[str]] = Field(None) value: Union[Optional[Union[IssueType, PlatformType, int, str]], Optional[List[Union[IssueType, PlatformType, int, str]]]] = Field(...) type: FilterType = Field(...) @@ -534,13 +531,10 @@ class _SessionSearchFilterSchema(__MixedSearchFilter): class SessionsSearchPayloadSchema(BaseModel): events: List[_SessionSearchEventSchema] = Field([]) filters: List[_SessionSearchFilterSchema] = Field([]) - # custom:dict=Field(...) - # rangeValue:str=Field(...) startDate: int = Field(None) endDate: int = Field(None) sort: str = Field(default="startTs") order: str = Field(default="DESC") - # platform: Optional[PlatformType] = Field(None) events_order: Optional[SearchEventOrder] = Field(default=SearchEventOrder._then) class Config: