feat(chalice): try to ignore dashboard calls for /chart for clickMaps

This commit is contained in:
Taha Yassine Kraiem 2023-02-02 16:02:22 +01:00
parent 0ad393ae06
commit e421589b8f
4 changed files with 15 additions and 26 deletions

View file

@ -456,8 +456,8 @@ def get_card(metric_id, project_id, user_id, flatten: bool = True, include_data:
query = cur.mogrify(
f"""SELECT metric_id, project_id, user_id, name, is_public, created_at, deleted_at, edited_at, metric_type,
view_type, metric_of, metric_value, metric_format, is_pinned, default_config,
thumbnail, default_config AS config,
series, dashboards, owner_email {',data' if include_data else ''}
default_config AS config,series, dashboards, owner_email
{',data' if include_data else ''}
FROM metrics
LEFT JOIN LATERAL (SELECT COALESCE(jsonb_agg(metric_series.* ORDER BY index),'[]'::jsonb) AS series
FROM metric_series

View file

@ -231,16 +231,9 @@ def get_custom_metric_errors_list(projectId: int, metric_id: int,
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardChartSchema = Body(...),
context: schemas.CurrentContext = Depends(OR_context)):
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
print("--- headers ---")
print(request.headers)
print(request.headers.get('REFERER'))
print(request.headers.get('referer'))
print(request.headers.get('Referer'))
import re
pattern = re.compile("[0-9]+\/dashboard\/[0-9]+$")
from_dashboard = pattern.match(request.headers.get('REFERER')) if request.headers.get('REFERER') \
else False
print(f"from_dashboard:{from_dashboard}")
from_dashboard = re.match(r".*\/[0-9]+\/dashboard\/[0-9]+$", request.headers.get('referer')) is not None \
if request.headers.get('referer') else False
data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data, from_dashboard=from_dashboard)
return {"data": data}

View file

@ -206,18 +206,18 @@ def get_sessions(project_id, user_id, metric_id, data: schemas.CardSessionsSchem
if metric is None:
return None
results = []
is_click_map = False
if __is_click_map(metric) and raw_metric.get("data") is not None:
is_click_map = True
# is_click_map = False
# if __is_click_map(metric) and raw_metric.get("data") is not None:
# is_click_map = True
for s in metric.series:
s.filter.startDate = data.startTimestamp
s.filter.endDate = data.endTimestamp
s.filter.limit = data.limit
s.filter.page = data.page
if is_click_map:
results.append(
{"seriesId": s.series_id, "seriesName": s.name, "total": 1, "sessions": [raw_metric["data"]]})
break
# if is_click_map:
# results.append(
# {"seriesId": s.series_id, "seriesName": s.name, "total": 1, "sessions": [raw_metric["data"]]})
# break
results.append({"seriesId": s.series_id, "seriesName": s.name,
**sessions.search_sessions(data=s.filter, project_id=project_id, user_id=user_id)})
@ -512,8 +512,8 @@ def get_card(metric_id, project_id, user_id, flatten: bool = True, include_data:
query = cur.mogrify(
f"""SELECT metric_id, project_id, user_id, name, is_public, created_at, deleted_at, edited_at, metric_type,
view_type, metric_of, metric_value, metric_format, is_pinned, default_config,
thumbnail, default_config AS config,
series, dashboards, owner_email {',data' if include_data else ''}
default_config AS config,series, dashboards, owner_email
{',data' if include_data else ''}
FROM metrics
LEFT JOIN LATERAL (SELECT COALESCE(jsonb_agg(metric_series.* ORDER BY index),'[]'::jsonb) AS series
FROM metric_series

View file

@ -233,13 +233,9 @@ def get_custom_metric_errors_list(projectId: int, metric_id: int,
def get_card_chart(projectId: int, metric_id: int, request: Request, data: schemas.CardChartSchema = Body(...),
context: schemas.CurrentContext = Depends(OR_context)):
# TODO: remove this when UI is able to stop this endpoint calls for clickMap
print("--- headers ---")
print(request.headers)
import re
pattern = re.compile("[0-9]+\/dashboard\/[0-9]+$")
from_dashboard = pattern.match(request.headers.get('REFERER')) if request.headers.get('REFERER') \
else False
print(f"from_dashboard:{from_dashboard}")
from_dashboard = re.match(r".*\/[0-9]+\/dashboard\/[0-9]+$", request.headers.get('referer')) is not None \
if request.headers.get('referer') else False
data = custom_metrics.make_chart_from_card(project_id=projectId, user_id=context.user_id, metric_id=metric_id,
data=data, from_dashboard=from_dashboard)
return {"data": data}