From 0cf115b2de30ddbcda956dd4ac2725c016ef32e6 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 25 Apr 2021 18:32:06 -0700 Subject: [PATCH] Load lookup database only once. --- lib/request.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/request.js b/lib/request.js index b30a710d..e5527f7d 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);