Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Load lookup database only once.

Mike Cao0cf115b2de30
diff --git a/lib/request.js b/lib/request.js
index b30a710df..e5527f7de 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -12,6 +12,8 @@ import {
MOBILE_SCREEN_WIDTH,
} from './constants';
+let lookup;
+
export function getIpAddress(req) {
// Cloudflare
if (req.headers['cf-connecting-ip']) {
@@ -61,7 +63,9 @@ export async function getCountry(req, ip) {
}
// Database lookup
- const lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb'));
+ if (!lookup) {
+ lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb'));
+ }
const result = lookup.get(ip);