MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / findProfilesCore

Function findProfilesCore

packages/db/src/services/profile.service.ts:390–471  ·  view source on GitHub ↗
(
  input: FindProfilesInput
)

Source from the content-addressed store, hash-verified

388}
389
390export function findProfilesCore(
391 input: FindProfilesInput
392): Promise<IClickhouseProfile[]> {
393 const pid = sqlstring.escape(input.projectId);
394 const conditions: string[] = [`project_id = ${pid}`];
395
396 if (input.email) {
397 conditions.push(`email ILIKE ${sqlstring.escape(`%${input.email}%`)}`);
398 }
399 if (input.name) {
400 const nameClause = profileSearchSql(input.name);
401 if (nameClause) conditions.push(nameClause);
402 }
403 if (input.country) {
404 conditions.push(
405 `properties['country'] = ${sqlstring.escape(input.country)}`
406 );
407 }
408 if (input.city) {
409 conditions.push(`properties['city'] = ${sqlstring.escape(input.city)}`);
410 }
411 if (input.device) {
412 conditions.push(`properties['device'] = ${sqlstring.escape(input.device)}`);
413 }
414 if (input.browser) {
415 conditions.push(
416 `properties['browser'] = ${sqlstring.escape(input.browser)}`
417 );
418 }
419
420 if (input.inactiveDays !== undefined) {
421 const days = Math.floor(input.inactiveDays);
422 conditions.push(`id NOT IN (
423 SELECT DISTINCT profile_id FROM ${TABLE_NAMES.events}
424 WHERE project_id = ${pid}
425 AND profile_id != ''
426 AND created_at >= now() - INTERVAL ${days} DAY
427 )`);
428 }
429
430 if (input.minSessions !== undefined) {
431 const min = Math.floor(input.minSessions);
432 conditions.push(`id IN (
433 SELECT profile_id FROM ${TABLE_NAMES.sessions}
434 WHERE project_id = ${pid}
435 AND sign = 1
436 AND profile_id != ''
437 GROUP BY profile_id
438 HAVING count() >= ${min}
439 )`);
440 }
441
442 if (input.performedEvent) {
443 conditions.push(`id IN (
444 SELECT DISTINCT profile_id FROM ${TABLE_NAMES.events}
445 WHERE project_id = ${pid}
446 AND name = ${sqlstring.escape(input.performedEvent)}
447 )`);

Callers 5

registerProfileToolsFunction · 0.90
profiles.test.tsFile · 0.90
findProfilesFunction · 0.90
base.tsFile · 0.90
profile.tsFile · 0.90

Calls 5

buildFilterWhereFunction · 0.90
chQueryFunction · 0.90
profileSearchSqlFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected