1+ import { existsSync } from "fs" ;
12import { SINGLE_TENANT_ORG_ID } from "@/lib/constants" ;
23import { isServiceError } from "@/lib/utils" ;
34import { __unsafePrisma } from "@/prisma" ;
@@ -10,17 +11,25 @@ const logger = createLogger('service-ping');
1011
1112const SERVICE_PING_INTERVAL_MS = 24 * 60 * 60 * 1000 ; // 1 day
1213
14+
1315export const syncWithLighthouse = async ( orgId : number ) => {
1416 // Look up the activation code from the License record
1517 const license = await __unsafePrisma . license . findUnique ( {
1618 where : { orgId } ,
1719 } ) ;
1820
19- const userCount = await __unsafePrisma . userToOrg . count ( {
20- where : {
21- orgId,
22- } ,
23- } ) ;
21+ const [ userCount , repoCount ] = await Promise . all ( [
22+ __unsafePrisma . userToOrg . count ( {
23+ where : {
24+ orgId,
25+ } ,
26+ } ) ,
27+ __unsafePrisma . repo . count ( {
28+ where : {
29+ orgId,
30+ } ,
31+ } ) ,
32+ ] ) ;
2433
2534 const activationCode = license ?. activationCode
2635 ? decryptActivationCode ( license . activationCode )
@@ -30,6 +39,9 @@ export const syncWithLighthouse = async (orgId: number) => {
3039 installId : env . SOURCEBOT_INSTALL_ID ,
3140 version : SOURCEBOT_VERSION ,
3241 userCount,
42+ repoCount,
43+ deploymentType : inferDeploymentType ( ) ,
44+ isTelemetryEnabled : env . SOURCEBOT_TELEMETRY_DISABLED === 'false' ,
3345 ...( activationCode && { activationCode } ) ,
3446 } ;
3547
@@ -111,3 +123,13 @@ export const startServicePingCronJob = () => {
111123 SERVICE_PING_INTERVAL_MS
112124 ) ;
113125} ;
126+
127+ const inferDeploymentType = ( ) : string => {
128+ if ( process . env . KUBERNETES_SERVICE_HOST ) {
129+ return 'kubernetes' ;
130+ }
131+ if ( existsSync ( '/.dockerenv' ) ) {
132+ return 'docker' ;
133+ }
134+ return 'other' ;
135+ } ;
0 commit comments