Repository: getsentry/sentry

Issue:
Rm trend sort code
Only tangentially related to this project, but we can clean up the [trend sort](https://github.com/getsentry/sentry/pull/23106) code as it's unused. 


Discussion:

Resolving patch:
diff --git a/src/sentry/features/__init__.py b/src/sentry/features/__init__.py
--- a/src/sentry/features/__init__.py
+++ b/src/sentry/features/__init__.py
@@ -89,7 +89,6 @@
 default_manager.add("organizations:sql-format", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:issue-details-tag-improvements", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:issue-list-removal-action", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
-default_manager.add("organizations:issue-list-trend-sort", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:issue-list-better-priority-sort", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:issue-platform", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:issue-search-allow-postgres-only-search", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
diff --git a/src/sentry/search/snuba/executors.py b/src/sentry/search/snuba/executors.py
--- a/src/sentry/search/snuba/executors.py
+++ b/src/sentry/search/snuba/executors.py
@@ -45,7 +45,6 @@
     group_categories_from,
 )
 from sentry.models import Environment, Group, Organization, Project
-from sentry.search.events.fields import DateArg
 from sentry.search.events.filter import convert_search_filter_to_snuba_query, format_search_filter
 from sentry.search.utils import validate_cdc_search_filters
 from sentry.utils import json, metrics, snuba
@@ -453,18 +452,6 @@ def has_sort_strategy(self, sort_by: str) -> bool:
         return sort_by in self.sort_strategies.keys()
 
 
-def trend_aggregation(start: datetime, end: datetime) -> Sequence[str]:
-    middle_date = start + timedelta(seconds=(end - start).total_seconds() * 0.5)
-    middle = datetime.strftime(middle_date, DateArg.date_format)
-
-    agg_range_1 = f"countIf(greater(toDateTime('{middle}'), timestamp))"
-    agg_range_2 = f"countIf(lessOrEquals(toDateTime('{middle}'), timestamp))"
-    return [
-        f"if(greater({agg_range_1}, 0), divide({agg_range_2}, {agg_range_1}), 0)",
-        "",
-    ]
-
-
 def better_priority_aggregation(
     start: datetime,
     end: datetime,
@@ -497,7 +484,6 @@ class PostgresSnubaQueryExecutor(AbstractQueryExecutor):
         "new": "first_seen",
         "priority": "priority",
         "user": "user_count",
-        "trend": "trend",
         # We don't need a corresponding snuba field here, since this sort only happens
         # in Postgres
         "inbox": "",
@@ -513,7 +499,6 @@ class PostgresSnubaQueryExecutor(AbstractQueryExecutor):
         # Only makes sense with WITH TOTALS, returns 1 for an individual group.
         "total": ["uniq", ISSUE_FIELD_NAME],
         "user_count": ["uniq", "tags[sentry:user]"],
-        "trend": trend_aggregation,
         "better_priority": better_priority_aggregation,
     }
 


Test patch:
diff --git a/tests/snuba/api/endpoints/test_organization_group_index.py b/tests/snuba/api/endpoints/test_organization_group_index.py
--- a/tests/snuba/api/endpoints/test_organization_group_index.py
+++ b/tests/snuba/api/endpoints/test_organization_group_index.py
@@ -171,67 +171,6 @@ def test_sort_by_better_priority(self):
         assert len(response.data) == 2
         assert [item["id"] for item in response.data] == [str(group.id), str(group_2.id)]
 
-    def test_sort_by_trend(self):
-        group = self.store_event(
-            data={
-                "timestamp": iso_format(before_now(seconds=10)),
-                "fingerprint": ["group-1"],
-            },
-            project_id=self.project.id,
-        ).group
-        self.store_event(
-            data={
-                "timestamp": iso_format(before_now(seconds=10)),
-                "fingerprint": ["group-1"],
-            },
-            project_id=self.project.id,
-        )
-        self.store_event(
-            data={
-                "timestamp": iso_format(before_now(hours=13)),
-                "fingerprint": ["group-1"],
-            },
-            project_id=self.project.id,
-        )
-
-        group_2 = self.store_event(
-            data={
-                "timestamp": iso_format(before_now(seconds=5)),
-                "fingerprint": ["group-2"],
-            },
-            project_id=self.project.id,
-        ).group
-        self.store_event(
-            data={
-                "timestamp": iso_format(before_now(hours=13)),
-                "fingerprint": ["group-2"],
-            },
-            project_id=self.project.id,
-        )
-        self.login_as(user=self.user)
-
-        response = self.get_success_response(
-            sort="trend",
-            query="is:unresolved",
-            limit=1,
-            start=iso_format(before_now(days=1)),
-            end=iso_format(before_now(seconds=1)),
-        )
-        assert len(response.data) == 1
-        assert [item["id"] for item in response.data] == [str(group.id)]
-
-        header_links = parse_link_header(response["Link"])
-        cursor = [link for link in header_links.values() if link["rel"] == "next"][0]["cursor"]
-        response = self.get_success_response(
-            sort="trend",
-            query="is:unresolved",
-            limit=1,
-            start=iso_format(before_now(days=1)),
-            end=iso_format(before_now(seconds=1)),
-            cursor=cursor,
-        )
-        assert [item["id"] for item in response.data] == [str(group_2.id)]
-
     def test_sort_by_inbox(self):
         group_1 = self.store_event(
             data={
diff --git a/tests/snuba/search/test_backend.py b/tests/snuba/search/test_backend.py
--- a/tests/snuba/search/test_backend.py
+++ b/tests/snuba/search/test_backend.py
@@ -1792,82 +1792,6 @@ def test_sort_multi_project(self):
         results = self.make_query([self.project, self.project2], sort_by="user")
         assert list(results) == [self.group1, self.group2, self.group_p2]
 
-    def test_sort_trend(self):
-        start = self.group1.first_seen - timedelta(days=1)
-        end = before_now(days=1).replace(tzinfo=pytz.utc)
-        middle = start + ((end - start) / 2)
-        self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group1"],
-                "event_id": "2" * 32,
-                "message": "something",
-                "timestamp": iso_format(self.base_datetime),
-            },
-            project_id=self.project.id,
-        )
-        self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group1"],
-                "event_id": "3" * 32,
-                "message": "something",
-                "timestamp": iso_format(self.base_datetime),
-            },
-            project_id=self.project.id,
-        )
-
-        fewer_events_group = self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group4"],
-                "event_id": "4" * 32,
-                "message": "something",
-                "timestamp": iso_format(middle - timedelta(days=1)),
-            },
-            project_id=self.project.id,
-        ).group
-        self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group4"],
-                "event_id": "5" * 32,
-                "message": "something",
-                "timestamp": iso_format(middle - timedelta(days=1)),
-            },
-            project_id=self.project.id,
-        )
-        self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group4"],
-                "event_id": "6" * 32,
-                "message": "something",
-                "timestamp": iso_format(self.base_datetime),
-            },
-            project_id=self.project.id,
-        )
-
-        no_before_group = self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group5"],
-                "event_id": "3" * 32,
-                "message": "something",
-                "timestamp": iso_format(self.base_datetime),
-            },
-            project_id=self.project.id,
-        ).group
-        no_after_group = self.store_event(
-            data={
-                "fingerprint": ["put-me-in-group6"],
-                "event_id": "4" * 32,
-                "message": "something",
-                "timestamp": iso_format(middle - timedelta(days=1)),
-            },
-            project_id=self.project.id,
-        ).group
-
-        self.set_up_multi_project()
-        results = self.make_query([self.project], sort_by="trend", date_from=start, date_to=end)
-        assert results[:2] == [self.group1, fewer_events_group]
-        # These will be arbitrarily ordered since their trend values are all 0
-        assert set(results[2:]) == {self.group2, no_before_group, no_after_group}
-
     def test_in_syntax_is_invalid(self):
         with pytest.raises(InvalidSearchQuery, match='"in" syntax invalid for "is" search'):
             self.make_query(search_filter_query="is:[unresolved, resolved]")