Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(event): smaller limits for event list api (#60124)

Nick Best54b60f558bc4
diff --git a/posthog/api/event.py b/posthog/api/event.py
index 143441a26a1b..438f06dddc8c 100644
--- a/posthog/api/event.py
+++ b/posthog/api/event.py
@@ -26,7 +26,7 @@ from rest_framework_csv import renderers as csvrenderers
from posthog.schema import ProductKey
from posthog.hogql import ast
-from posthog.hogql.constants import DEFAULT_RETURNED_ROWS, MAX_SELECT_RETURNED_ROWS
+from posthog.hogql.constants import DEFAULT_RETURNED_ROWS
from posthog.hogql.property_utils import create_property_conditions
from posthog.hogql.query import execute_hogql_query
@@ -70,7 +70,8 @@ EVENT_VALUES_COUNTER = Counter(
labelnames=["has_event_name", "auth"],
)
-QUERY_DEFAULT_EXPORT_LIMIT = 3_500
+QUERY_DEFAULT_EXPORT_LIMIT = 1_000
+EVENT_LIST_MAX_LIMIT = 1_000
# Progressive time windows in seconds: 1min, 5min, 15min, 1hr, 6hr, 24hr
EVENT_LIST_TIME_WINDOWS = [60, 300, 900, 3600, 21600, 86400]
@@ -273,7 +274,7 @@ class EventViewSet(
else:
limit = DEFAULT_RETURNED_ROWS
- limit = min(limit, MAX_SELECT_RETURNED_ROWS)
+ limit = min(limit, EVENT_LIST_MAX_LIMIT)
try:
offset = int(request.GET["offset"]) if request.GET.get("offset") else 0
diff --git a/posthog/api/test/test_event.py b/posthog/api/test/test_event.py
index fd7b7779417e..24efa35c0d98 100644
--- a/posthog/api/test/test_event.py
+++ b/posthog/api/test/test_event.py
@@ -923,6 +923,15 @@ class TestEvents(ClickhouseTestMixin, APIBaseTest):
response = self.client.get(f"/api/projects/{self.team.id}/events/?limit=2").json()
assert len(response["results"]) == 2
+ @patch("posthog.api.event.EVENT_LIST_MAX_LIMIT", 2)
+ def test_limit_is_capped_at_event_list_max(self):
+ _create_person(team=self.team, distinct_ids=["1"], is_identified=True)
+ for _i in range(3):
+ _create_event(event="$pageview", team=self.team, distinct_id="1", properties={"$ip": "8.8.8.8"})
+
+ response = self.client.get(f"/api/projects/{self.team.id}/events/?limit=50000").json()
+ assert len(response["results"]) == 2
+
def test_get_events_with_specified_token(self):
_, _, user2 = User.objects.bootstrap("Test", "[email protected]", None)
assert user2.team is not None
@@ -1290,6 +1299,7 @@ class TestEventListTimeWindowOptimization(ClickhouseTestMixin, APIBaseTest):
# Should NOT update cache when data is identical (optimization)
mock_cache.set.assert_not_called()
+ @patch("posthog.api.event.EVENT_LIST_MAX_LIMIT", 6000)
@patch("posthog.api.event.cache")
@patch("posthog.api.event.query_events_list")
def test_ignores_cached_window_when_result_count_below_threshold(self, mock_query_events_list, mock_cache):