Skip to content

Commit 82c4186

Browse files
committed
fix: CPU on cache
1 parent 606cbe2 commit 82c4186

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

apps/basket/src/lib/event-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function insertError(
5959

6060
const { anonymizedIP, country, region } = geoData;
6161
const { browserName, browserVersion, osName, osVersion, deviceType } =
62-
await parseUserAgent(userAgent);
62+
parseUserAgent(userAgent);
6363

6464
const errorEvent: ErrorEvent = {
6565
id: randomUUID(),
@@ -141,7 +141,7 @@ export async function insertWebVitals(
141141

142142
const { country, region } = await getGeo(ip);
143143
const { browserName, browserVersion, osName, osVersion, deviceType } =
144-
await parseUserAgent(userAgent);
144+
parseUserAgent(userAgent);
145145

146146
const webVitalsEvent: WebVitalsEvent = {
147147
id: randomUUID(),
@@ -331,7 +331,7 @@ export function insertTrackEvent(
331331
deviceType,
332332
deviceBrand,
333333
deviceModel,
334-
} = await parseUserAgent(userAgent);
334+
} = parseUserAgent(userAgent);
335335
const now = Date.now();
336336

337337
const trackEvent: AnalyticsEvent = {

apps/basket/src/utils/user-agent.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* and platform identification.
66
*/
77

8-
import { cacheable } from "@databuddy/redis";
98
import { bots } from "@databuddy/shared/lists/bots";
109
import { UAParser } from "ua-parser-js";
1110
import { logger } from "../lib/logger";
@@ -22,9 +21,9 @@ export type UserAgentInfo = {
2221
};
2322

2423
/**
25-
* Parse user agent to extract useful information (uncached)
24+
* Parse user agent to extract useful information
2625
*/
27-
function _parseUserAgent(userAgent: string): {
26+
export function parseUserAgent(userAgent: string): {
2827
browserName?: string;
2928
browserVersion?: string;
3029
osName?: string;
@@ -48,7 +47,7 @@ function _parseUserAgent(userAgent: string): {
4847
try {
4948
const parser = new UAParser(userAgent);
5049
const result = parser.getResult();
51-
50+
5251
return {
5352
browserName: result.browser.name || undefined,
5453
browserVersion: result.browser.version || undefined,
@@ -72,16 +71,6 @@ function _parseUserAgent(userAgent: string): {
7271
}
7372
}
7473

75-
/**
76-
* Parse user agent to extract useful information (cached)
77-
*/
78-
export const parseUserAgent = cacheable(_parseUserAgent, {
79-
expireInSec: 3600,
80-
prefix: "ua_parse",
81-
staleWhileRevalidate: true,
82-
staleTime: 1800,
83-
});
84-
8574
export function detectBot(
8675
userAgent: string,
8776
request: Request

0 commit comments

Comments
 (0)