| 471 | } |
| 472 | |
| 473 | export async function getProfileWithEvents( |
| 474 | projectId: string, |
| 475 | profileId: string, |
| 476 | eventLimit = 10 |
| 477 | ): Promise<{ |
| 478 | profile: IClickhouseProfile | null; |
| 479 | recent_events: IClickhouseEvent[]; |
| 480 | }> { |
| 481 | const [profiles, recent_events] = await Promise.all([ |
| 482 | chQuery<IClickhouseProfile>(` |
| 483 | SELECT ${PROFILE_COLUMNS} |
| 484 | FROM ${TABLE_NAMES.profiles} FINAL |
| 485 | WHERE project_id = ${sqlstring.escape(projectId)} AND id = ${sqlstring.escape(profileId)} |
| 486 | LIMIT 1 |
| 487 | `), |
| 488 | clix(ch) |
| 489 | .select<IClickhouseEvent>([]) |
| 490 | .from(TABLE_NAMES.events) |
| 491 | .where('project_id', '=', projectId) |
| 492 | .where('profile_id', '=', profileId) |
| 493 | .orderBy('created_at', 'DESC') |
| 494 | .limit(eventLimit) |
| 495 | .execute(), |
| 496 | ]); |
| 497 | |
| 498 | return { profile: profiles[0] ?? null, recent_events }; |
| 499 | } |
| 500 | |
| 501 | export function getProfileSessionsCore( |
| 502 | projectId: string, |