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

Function getProfileFields

packages/db/src/services/chart.service.ts:498–547  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

496 // Collect all profile fields used in filters and breakdowns
497 // Extract top-level field names (e.g., 'properties' from 'profile.properties.os')
498 const getProfileFields = () => {
499 const fields = new Set<string>();
500
501 // Always need id for the join
502 fields.add('id');
503
504 // Collect from filters
505 event.filters
506 .filter((f) => f.name.startsWith('profile.'))
507 .forEach((f) => {
508 const fieldName = f.name.replace('profile.', '').split('.')[0];
509 if (fieldName && fieldName === 'properties') {
510 fields.add('properties');
511 } else if (
512 fieldName &&
513 [
514 'email',
515 'first_name',
516 'last_name',
517 'created_at',
518 'last_seen_at',
519 ].includes(fieldName)
520 ) {
521 fields.add(fieldName);
522 }
523 });
524
525 // Collect from breakdowns
526 breakdowns
527 .filter((b) => b.name.startsWith('profile.'))
528 .forEach((b) => {
529 const fieldName = b.name.replace('profile.', '').split('.')[0];
530 if (fieldName && fieldName === 'properties') {
531 fields.add('properties');
532 } else if (
533 fieldName &&
534 [
535 'email',
536 'first_name',
537 'last_name',
538 'created_at',
539 'last_seen_at',
540 ].includes(fieldName)
541 ) {
542 fields.add(fieldName);
543 }
544 });
545
546 return Array.from(fields);
547 };
548
549 // Create profiles CTE if profiles are needed (to avoid duplicating the heavy profile join)
550 // Only select the fields that are actually used

Callers 2

getChartSqlFunction · 0.85
getAggregateChartSqlFunction · 0.85

Calls 3

replaceMethod · 0.80
addMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected