MCPcopy
hub / github.com/msgbyte/tianji / findSession

Function findSession

src/server/model/telemetry.ts:82–129  ·  view source on GitHub ↗
(req: Request, url: string)

Source from the content-addressed store, hash-verified

80}
81
82async function findSession(req: Request, url: string) {
83 const { hostname } = new URL(url);
84 const workspaceId = req.params.workspaceId;
85 if (!workspaceId) {
86 throw new Error('Not found workspaceId');
87 }
88
89 const {
90 userAgent,
91 browser,
92 os,
93 ip,
94 country,
95 subdivision1,
96 subdivision2,
97 city,
98 longitude,
99 latitude,
100 accuracyRadius,
101 } = await getRequestInfo(req);
102
103 const sessionId = hashUuid(workspaceId, hostname, ip, userAgent!);
104
105 let session = await loadSession(sessionId);
106 if (!session) {
107 session = await prisma.telemetrySession.upsert({
108 where: { id: sessionId },
109 create: {
110 id: sessionId,
111 workspaceId,
112 hostname,
113 browser,
114 os,
115 ip,
116 country,
117 subdivision1,
118 subdivision2,
119 city,
120 longitude,
121 latitude,
122 accuracyRadius,
123 },
124 update: {},
125 });
126 }
127
128 return session;
129}
130
131const { get: getTelemetrySessionFromCache, del: delTelemetrySessionCache } =
132 buildQueryWithCache('telemetrySession', async (sessionId: string): Promise<TelemetrySession | null> => {

Callers 4

recordTelemetryEventFunction · 0.70
website.tsFile · 0.50
application.tsFile · 0.50
website.test.tsFile · 0.50

Calls 4

getRequestInfoFunction · 0.85
hashUuidFunction · 0.85
loadSessionFunction · 0.70
upsertMethod · 0.45

Tested by

no test coverage detected