mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 12:21:02 +01:00
Really fix event limit (#2870)
* Only grab recent events in Events list * Really limit amount of data we query for event list * typing * better test
This commit is contained in:
parent
9fe164076a
commit
93fff3ea00
@ -37,7 +37,9 @@ class ClickhouseEventsViewSet(EventViewSet):
|
||||
|
||||
def _query_events_list(self, filter: Filter, team: Team, request: Request, long_date_from: bool = False) -> List:
|
||||
limit = "LIMIT 101"
|
||||
conditions, condition_params = determine_event_conditions(request.GET.dict(), long_date_from)
|
||||
conditions, condition_params = determine_event_conditions(
|
||||
{"after": (now() - timedelta(days=1)).isoformat(), **request.GET.dict()}, long_date_from
|
||||
)
|
||||
prop_filters, prop_filter_params = parse_prop_clauses(filter.properties, team.pk)
|
||||
|
||||
if request.GET.get("action_id"):
|
||||
|
@ -1,5 +1,8 @@
|
||||
from datetime import timedelta
|
||||
from unittest.mock import Mock, patch
|
||||
from uuid import uuid4
|
||||
|
||||
from django.utils import timezone
|
||||
from freezegun import freeze_time
|
||||
|
||||
from ee.clickhouse.models.event import create_event
|
||||
@ -31,3 +34,16 @@ class ClickhouseTestEventApi(
|
||||
):
|
||||
def test_live_action_events(self):
|
||||
pass
|
||||
|
||||
@patch("ee.clickhouse.views.events.sync_execute")
|
||||
def test_optimize_query(self, patch_sync_execute):
|
||||
# For ClickHouse we normally only query the last day,
|
||||
# but if a user doesn't have many events we still want to return events that are older
|
||||
patch_sync_execute.return_value = [("event", "d", "{}", timezone.now(), "d", "d", "d")]
|
||||
response = self.client.get("/api/event/").json()
|
||||
self.assertEqual(len(response["results"]), 1)
|
||||
self.assertEqual(patch_sync_execute.call_count, 2)
|
||||
|
||||
patch_sync_execute.return_value = [("event", "d", "{}", timezone.now(), "d", "d", "d") for _ in range(0, 100)]
|
||||
response = self.client.get("/api/event/").json()
|
||||
self.assertEqual(patch_sync_execute.call_count, 3)
|
||||
|
@ -339,16 +339,6 @@ def test_event_api_factory(event_factory, person_factory, action_factory):
|
||||
|
||||
self.assertEqual(len(response_person_1["result"]), 1)
|
||||
|
||||
def test_optimize_query(self):
|
||||
# For ClickHouse we normally only query the last day,
|
||||
# but if a user doesn't have many events we still want to return events that are older
|
||||
event_factory(
|
||||
event="pageview", timestamp=timezone.now() - timedelta(days=25), team=self.team, distinct_id="user1"
|
||||
)
|
||||
event_factory(event="pageview", timestamp=timezone.now(), team=self.team, distinct_id="user1")
|
||||
response = self.client.get("/api/event/").json()
|
||||
self.assertEqual(len(response["results"]), 2)
|
||||
|
||||
return TestEvents
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user