mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-07-18 21:05:42 +00:00
Cache NodeId and Location (#35)
* Cache NodeId and Location * Fix frontend dependency vuln
This commit is contained in:
@@ -7,7 +7,7 @@ export interface Location {
|
||||
city: Types.City;
|
||||
}
|
||||
|
||||
const cache = new Map<string, Location>();
|
||||
const cache = new Map<string, Maybe<Location>>();
|
||||
|
||||
export async function locate(ip: string): Promise<Maybe<Location>> {
|
||||
if (ip === '127.0.0.1') {
|
||||
@@ -18,17 +18,19 @@ export async function locate(ip: string): Promise<Maybe<Location>> {
|
||||
});
|
||||
}
|
||||
|
||||
const cached = cache.get(ip);
|
||||
|
||||
if (cached) {
|
||||
return Promise.resolve(cached);
|
||||
if (cache.has(ip)) {
|
||||
return Promise.resolve(cache.get(ip));
|
||||
}
|
||||
|
||||
const cached = cache.get(ip);
|
||||
|
||||
return new Promise<Maybe<Location>>((resolve, _) => {
|
||||
iplocation(ip, (err, result) => {
|
||||
if (err) {
|
||||
console.error(`Couldn't locate ${ip}`);
|
||||
|
||||
cache.set(ip, null);
|
||||
|
||||
return resolve(null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user