diff --git a/api/chalicelib/core/integrations_manager.py b/api/chalicelib/core/integrations_manager.py index ef63a7d96..5cc15cfba 100644 --- a/api/chalicelib/core/integrations_manager.py +++ b/api/chalicelib/core/integrations_manager.py @@ -27,7 +27,7 @@ def __get_default_integration(user_id): current_integrations["jira"] else None -def get_integration(tenant_id, user_id, tool=None): +def get_integration(tenant_id, user_id, tool=None, for_delete=False): if tool is None: tool = __get_default_integration(user_id=user_id) if tool is None: @@ -37,7 +37,7 @@ def get_integration(tenant_id, user_id, tool=None): return {"errors": [f"issue tracking tool not supported yet, available: {SUPPORTED_TOOLS}"]}, None if tool == integration_jira_cloud.PROVIDER: integration = integration_jira_cloud.JIRAIntegration(tenant_id=tenant_id, user_id=user_id) - if integration.integration is not None and not integration.integration.get("valid", True): + if not for_delete and integration.integration is not None and not integration.integration.get("valid", True): return {"errors": ["JIRA: connexion issue/unauthorized"]}, integration return None, integration elif tool == integration_github.PROVIDER: diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index e5a704298..6c846eb42 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -176,7 +176,7 @@ def _isUndefined_operator(op: schemas.SearchEventOperator): def search_sessions(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, errors_only=False, error_status=schemas.ErrorStatus.all, count_only=False, issue=None): if data.bookmarked: - data.startDate,data.endDate = sessions_favorite.get_start_end_timestamp(project_id,user_id) + data.startDate, data.endDate = sessions_favorite.get_start_end_timestamp(project_id, user_id) full_args, query_part = search_query_parts(data=data, error_status=error_status, errors_only=errors_only, favorite_only=data.bookmarked, issue=issue, project_id=project_id, @@ -523,12 +523,12 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr ss_constraints.append("ms.duration <= %(maxDuration)s") full_args["maxDuration"] = f.value[1] elif filter_type == schemas.FilterType.referrer: - extra_from += f"INNER JOIN {events.event_type.LOCATION.table} AS p USING(session_id)" + # extra_from += f"INNER JOIN {events.event_type.LOCATION.table} AS p USING(session_id)" if is_any: - extra_constraints.append('p.base_referrer IS NOT NULL') + extra_constraints.append('s.base_referrer IS NOT NULL') else: extra_constraints.append( - _multiple_conditions(f"p.base_referrer {op} %({f_k})s", f.value, is_not=is_not, value_key=f_k)) + _multiple_conditions(f"s.base_referrer {op} %({f_k})s", f.value, is_not=is_not, value_key=f_k)) elif filter_type == events.event_type.METADATA.ui_type: # get metadata list only if you need it if meta_keys is None: diff --git a/api/routers/core.py b/api/routers/core.py index f9ca28a4d..b3252e34a 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -491,7 +491,8 @@ def delete_default_issue_tracking_tool(context: schemas.CurrentContext = Depends def delete_jira_cloud(context: schemas.CurrentContext = Depends(OR_context)): error, integration = integrations_manager.get_integration(tool=integration_jira_cloud.PROVIDER, tenant_id=context.tenant_id, - user_id=context.user_id) + user_id=context.user_id, + for_delete=True) if error is not None: return error return {"data": integration.delete()} @@ -501,7 +502,8 @@ def delete_jira_cloud(context: schemas.CurrentContext = Depends(OR_context)): def delete_github(context: schemas.CurrentContext = Depends(OR_context)): error, integration = integrations_manager.get_integration(tool=integration_github.PROVIDER, tenant_id=context.tenant_id, - user_id=context.user_id) + user_id=context.user_id, + for_delete=True) if error is not None: return error return {"data": integration.delete()} diff --git a/ee/api/chalicelib/core/sessions_exp.py b/ee/api/chalicelib/core/sessions_exp.py index 58ce154b0..add1a790d 100644 --- a/ee/api/chalicelib/core/sessions_exp.py +++ b/ee/api/chalicelib/core/sessions_exp.py @@ -605,20 +605,16 @@ def search_query_parts_ch(data, error_status, errors_only, favorite_only, issue, ss_constraints.append("ms.duration <= %(maxDuration)s") full_args["maxDuration"] = f.value[1] elif filter_type == schemas.FilterType.referrer: - # extra_from += f"INNER JOIN {events.event_type.LOCATION.table} AS p USING(session_id)" if is_any: - referrer_constraint = 'isNotNull(r.base_referrer)' + extra_constraints.append('isNotNull(s.base_referrer)') + ss_constraints.append('isNotNull(ms.base_referrer)') else: - referrer_constraint = _multiple_conditions(f"r.base_referrer {op} %({f_k})s", f.value, - is_not=is_not, value_key=f_k) - referrer_constraint = f"""(SELECT DISTINCT session_id - FROM {MAIN_EVENTS_TABLE} AS r - WHERE {" AND ".join([f"r.{b}" for b in __events_where_basic])} - AND event_type='{__get_event_type(schemas.EventType.location)}' - AND {referrer_constraint})""" - # events_conditions_where.append(f"""main.session_id IN {referrer_constraint}""") - # extra_constraints.append(f"""s.session_id IN {referrer_constraint}""") - extra_from += f"\nINNER JOIN {referrer_constraint} AS referred ON(referred.session_id=s.session_id)" + extra_constraints.append( + _multiple_conditions(f"s.base_referrer {op} toString(%({f_k})s)", f.value, is_not=is_not, + value_key=f_k)) + ss_constraints.append( + _multiple_conditions(f"ms.base_referrer {op} toString(%({f_k})s)", f.value, is_not=is_not, + value_key=f_k)) elif filter_type == events.event_type.METADATA.ui_type: # get metadata list only if you need it if meta_keys is None: diff --git a/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql index c8028d677..8347a5c78 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -31,6 +31,7 @@ ALTER TABLE IF EXISTS alerts ALTER TABLE IF EXISTS sessions ADD COLUMN IF NOT EXISTS referrer text NULL DEFAULT NULL, ADD COLUMN IF NOT EXISTS base_referrer text NULL DEFAULT NULL; +CREATE INDEX IF NOT EXISTS sessions_base_referrer_gin_idx ON public.sessions USING GIN (base_referrer gin_trgm_ops); ALTER TABLE IF EXISTS events.performance ADD COLUMN IF NOT EXISTS host text NULL DEFAULT NULL, diff --git a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql index dab720b73..91cb307eb 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -604,6 +604,7 @@ $$ CREATE INDEX IF NOT EXISTS sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops); CREATE INDEX IF NOT EXISTS sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops); CREATE INDEX IF NOT EXISTS sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops); + CREATE INDEX IF NOT EXISTS sessions_base_referrer_gin_idx ON public.sessions USING GIN (base_referrer gin_trgm_ops); BEGIN ALTER TABLE public.sessions ADD CONSTRAINT web_browser_constraint CHECK ( diff --git a/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql index 537c2082a..b14b14f91 100644 --- a/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -31,6 +31,7 @@ ALTER TABLE IF EXISTS alerts ALTER TABLE IF EXISTS sessions ADD COLUMN IF NOT EXISTS referrer text NULL DEFAULT NULL, ADD COLUMN IF NOT EXISTS base_referrer text NULL DEFAULT NULL; +CREATE INDEX IF NOT EXISTS sessions_base_referrer_gin_idx ON public.sessions USING GIN (base_referrer gin_trgm_ops); ALTER TABLE IF EXISTS events.performance ADD COLUMN IF NOT EXISTS host text NULL DEFAULT NULL, diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index 77cab0e7b..c172c1d76 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -498,6 +498,8 @@ $$ CREATE INDEX sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops); CREATE INDEX sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops); CREATE INDEX sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops); + CREATE INDEX sessions_base_referrer_gin_idx ON public.sessions USING GIN (base_referrer gin_trgm_ops); + ALTER TABLE public.sessions ADD CONSTRAINT web_browser_constraint CHECK (