Skip to content

Commit

Permalink
Merge branch 'master' into feat/simplify-distinct-id-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 6, 2023
2 parents 677d5cc + 4c3f87d commit fedfb7d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -694,36 +694,6 @@
5 /* ... */) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_get_session_recordings.31
'
SELECT "posthog_persondistinctid"."id",
"posthog_persondistinctid"."team_id",
"posthog_persondistinctid"."person_id",
"posthog_persondistinctid"."distinct_id",
"posthog_persondistinctid"."version"
FROM "posthog_persondistinctid"
WHERE "posthog_persondistinctid"."person_id" IN (1,
2,
3,
4,
5 /* ... */) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_get_session_recordings.32
'
SELECT "posthog_persondistinctid"."id",
"posthog_persondistinctid"."team_id",
"posthog_persondistinctid"."person_id",
"posthog_persondistinctid"."distinct_id",
"posthog_persondistinctid"."version"
FROM "posthog_persondistinctid"
WHERE "posthog_persondistinctid"."person_id" IN (1,
2,
3,
4,
5 /* ... */) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_get_session_recordings.4
'
SELECT "posthog_team"."id",
Expand Down Expand Up @@ -3262,6 +3232,53 @@
5 /* ... */) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.195
'
SELECT "posthog_persondistinctid"."id",
"posthog_persondistinctid"."team_id",
"posthog_persondistinctid"."person_id",
"posthog_persondistinctid"."distinct_id",
"posthog_persondistinctid"."version",
"posthog_person"."id",
"posthog_person"."created_at",
"posthog_person"."properties_last_updated_at",
"posthog_person"."properties_last_operation",
"posthog_person"."team_id",
"posthog_person"."properties",
"posthog_person"."is_user_id",
"posthog_person"."is_identified",
"posthog_person"."uuid",
"posthog_person"."version"
FROM "posthog_persondistinctid"
INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id")
WHERE ("posthog_persondistinctid"."distinct_id" IN ('user1',
'user10',
'user2',
'user3',
'user4',
'user5',
'user6',
'user7',
'user8',
'user9')
AND "posthog_persondistinctid"."team_id" = 2) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.196
'
SELECT "posthog_persondistinctid"."id",
"posthog_persondistinctid"."team_id",
"posthog_persondistinctid"."person_id",
"posthog_persondistinctid"."distinct_id",
"posthog_persondistinctid"."version"
FROM "posthog_persondistinctid"
WHERE "posthog_persondistinctid"."person_id" IN (1,
2,
3,
4,
5 /* ... */) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'
---
# name: TestSessionRecordings.test_listing_recordings_is_not_nplus1_for_persons.2
'
SELECT "posthog_organizationmembership"."id",
Expand Down
71 changes: 2 additions & 69 deletions posthog/session_recordings/test/test_session_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,10 @@ def create_snapshot(
session_id,
timestamp,
team_id=None,
window_id="",
source=0,
has_full_snapshot=True,
type=2,
snapshot_data=None,
use_replay_table=True,
use_recording_table=False,
):
if team_id is None:
team_id = self.team.pk

snapshot = {
"timestamp": timestamp.timestamp() * 1000,
"has_full_snapshot": has_full_snapshot,
"type": type,
"data": {"source": source},
}

if snapshot_data:
snapshot.update(snapshot_data)

produce_replay_summary(
team_id=team_id,
session_id=session_id,
Expand All @@ -77,53 +60,6 @@ def create_snapshot(
last_timestamp=timestamp,
)

def create_snapshots(
self,
snapshot_count,
distinct_id,
session_id,
timestamp,
has_full_snapshot=True,
window_id="",
use_replay_table=True,
use_recording_table=False,
):
snapshots = []
for index in range(snapshot_count):
snapshots.append(
{
"type": 2 if has_full_snapshot else 3,
"data": {
"source": 0,
"texts": [],
"attributes": [],
"removes": [],
"adds": [
{
"parentId": 4,
"nextId": 386,
"node": {
"type": 2,
"tagName": "style",
"attributes": {"data-emotion": "css"},
"childNodes": [],
"id": 729,
},
}
],
},
"timestamp": (timestamp + timedelta(seconds=index)).timestamp() * 1000,
}
)

produce_replay_summary(
team_id=self.team.pk,
session_id=session_id,
distinct_id=distinct_id,
first_timestamp=timestamp,
last_timestamp=timestamp,
)

@snapshot_postgres_queries
def test_get_session_recordings(self):
twelve_distinct_ids: List[str] = [f"user_one_{i}" for i in range(12)]
Expand Down Expand Up @@ -274,8 +210,8 @@ def test_viewed_state_of_session_recording_version_1(self):
)
base_time = (now() - timedelta(days=1)).replace(microsecond=0)
SessionRecordingViewed.objects.create(team=self.team, user=self.user, session_id="1")
self.create_snapshot("u1", "1", base_time, use_recording_table=True)
self.create_snapshot("u1", "2", base_time + relativedelta(seconds=30), use_recording_table=True)
self.create_snapshot("u1", "1", base_time)
self.create_snapshot("u1", "2", base_time + relativedelta(seconds=30))
response = self.client.get(f"/api/projects/{self.team.id}/session_recordings")
response_data = response.json()
self.assertEqual(len(response_data["results"]), 2)
Expand Down Expand Up @@ -471,19 +407,16 @@ def test_session_ids_filter(self, use_recording_events: bool, api_version: int):
"user",
"1",
now() - relativedelta(days=1),
use_recording_table=use_recording_events,
)
self.create_snapshot(
"user",
"2",
now() - relativedelta(days=2),
use_recording_table=use_recording_events,
)
self.create_snapshot(
"user",
"3",
now() - relativedelta(days=3),
use_recording_table=use_recording_events,
)

# Fetch playlist
Expand Down

0 comments on commit fedfb7d

Please sign in to comment.