Skip to content

Commit

Permalink
fix: Fix database reload (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Shirokov authored May 26, 2021
1 parent 4209bb5 commit a8d534c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
19 changes: 13 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"Gregory Oschwald @oschwald"
],
"dependencies": {
"mmdb-lib": "1.2.0",
"mmdb-lib": "1.3.0",
"tiny-lru": "7.0.6"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const open = async <T>(
}

const cache = lru((opts && opts.cache && opts.cache.max) || 6000);
let reader = new Reader<T>(database, { cache });
const reader = new Reader<T>(database, { cache });

if (opts && !!opts.watchForUpdates) {
if (
Expand Down Expand Up @@ -63,9 +63,9 @@ export const open = async <T>(
if (!(await waitExists())) {
return;
}
const updateDatabase = await fs.readFile(filepath);
const updatedDatabase = await fs.readFile(filepath);
cache.clear();
reader = new Reader<T>(updateDatabase, { cache });
reader.load(updatedDatabase);
if (opts.watchForUpdatesHook) {
opts.watchForUpdatesHook();
}
Expand Down Expand Up @@ -94,4 +94,4 @@ export default {
validate: ip.validate,
};

export { Reader };
export { Reader };
7 changes: 7 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test data

Test data is installed via _git submodule_ from https://github.com/maxmind/MaxMind-DB.git. Execute following command in the project root:

```shell
git submodule update --init
```

0 comments on commit a8d534c

Please sign in to comment.